A request that does not have a valid action parameter cannot be processed. Specify a valid SOAP action.

Виктор Белянкин 0 Reputation points
2024-06-19T05:08:22.84+00:00

Hello!
Please tell me how to correctly execute the method using a Soap request
Code:
using System.Text;

public class Soap

{

public async static Task CallWebService()

{

    var _url = "http://192.168.88.51:80/reportserver/ReportService2010.asmx?wsdl";

    var _action = "http://192.168.88.51:80/reportserver/ReportService2010.asmx/DisableSubscription";

    string subscriptionID = "f7c5fe39-33b2-44be-82e2-f14fa91b79a4";

    string _soap = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\""

        + " xmlns:ns2=\"http://192.168.88.51:80/reportserver/ReportService2010.asmx/\""

        + " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\""

        + " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"

        + "<SOAP-ENV:Body>"

        + "<ns2:DisableDescription"

        + " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"

        + " <ns2:SubscriptionID xsi:type=\"xsd:string\">" + subscriptionID + "</ns2:SubscriptionID>"

        + "</ns2:DisableDescription>"

        + "</SOAP-ENV:Body>"

    + "</SOAP-ENV:Envelope>";

    string response = await CreateWebRequest(_url, _action, _soap);

}

private async static Task<string> CreateWebRequest(string url, string action, string soap)

{

    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("login", "pass");

    var handler = new HttpClientHandler { Credentials = credentials };

    HttpClient client = new(handler);

    client.BaseAddress = new Uri(url);

    Console.WriteLine($"SOAP Request:\n{soap}");

    using HttpContent content = new StringContent(soap, Encoding.UTF8, "application/soap+xml");

    using HttpRequestMessage request = new(HttpMethod.Post, url);

    request.Content = content;

    request.Headers.Add("SOAPAction", action);

    using HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

    Console.WriteLine($"SOAP Response:\n{await response.Content.ReadAsStringAsync()}");

    return await response.Content.ReadAsStringAsync();

}
```}

ConsoleWriteline:  
SOAP Request:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://192.168.88.51:80/reportserver/ReportService2010.asmx/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Body><ns2:DisableDescription SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <ns2:SubscriptionID xsi:type="xsd:string">f7c5fe39-33b2-44be-82e2-f14fa91b79a4</ns2:SubscriptionID></ns2:DisableDescription></SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP Response:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>A request that does not have a valid action parameter cannot be processed. Specify a valid SOAP action.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,561 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiale Xue - MSFT 42,061 Reputation points Microsoft Vendor
    2024-06-19T09:39:21.4266667+00:00

    Hi @Виктор Белянкин, Welcome to Microsoft Q&A,

    To resolve the error "A request that does not have a valid action parameter cannot be processed. Specify a valid SOAP action." in your SOAP request, you need to ensure that the SOAPAction header is correctly set and that the SOAP request body matches the expected structure of the web service.

    using System;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    
    public class Soap
    {
        public async static Task CallWebService()
        {
            var _url = "http://192.168.88.51:80/reportserver/ReportService2010.asmx";
            var _action = "http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/DisableSubscription";
    
            string subscriptionID = "f7c5fe39-33b2-44be-82e2-f14fa91b79a4";
    
            string _soap = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\""
                + " xmlns:ns2=\"http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer\""
                + " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\""
                + " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"
                + "<SOAP-ENV:Body>"
                + "<ns2:DisableSubscription>"
                + " <ns2:SubscriptionID>" + subscriptionID + "</ns2:SubscriptionID>"
                + "</ns2:DisableSubscription>"
                + "</SOAP-ENV:Body>"
                + "</SOAP-ENV:Envelope>";
    
            string response = await CreateWebRequest(_url, _action, _soap);
        }
    
        private async static Task<string> CreateWebRequest(string url, string action, string soap)
        {
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("login", "pass");
    
            var handler = new HttpClientHandler { Credentials = credentials };
            HttpClient client = new(handler);
    
            Console.WriteLine($"SOAP Request:\n{soap}");
    
            using HttpContent content = new StringContent(soap, Encoding.UTF8, "text/xml");
            using HttpRequestMessage request = new(HttpMethod.Post, url);
    
            request.Content = content;
            request.Headers.Add("SOAPAction", action);
    
            using HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
            string result = await response.Content.ReadAsStringAsync();
    
            Console.WriteLine($"SOAP Response:\n{result}");
    
            return result;
        }
    }
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments