Determine if the HTTP request is a soap request on HttpApplication.AuthenticateRequest

Do I have a way to find out if a request is a soap request in an AuthenticateRequest event for HttpApplication? Checking ServerVariables ["HTTP_SOAPACTION"] does not seem to work all the time.

public void Init(HttpApplication context) {
    context.AuthenticateRequest += new EventHandler(AuthenticateRequest);
}

protected void AuthenticateRequest(object sender, EventArgs e) {
    app = sender as HttpApplication;
    if (app.Request.ServerVariables["HTTP_SOAPACTION"] != null) {
        // a few requests do not enter here, but my webservice class still executing
        // ...
    }
}

I disabled HTTP POST and HTTP GET for web services in my web.config file.

<webServices>
    <protocols>
      <remove name="HttpGet" />
           <remove name="HttpPost" />
      <add name="AnyHttpSoap" />
    </protocols>
</webServices>

Finding ContentType for soap + xml only partially solves my problem. For instance,

Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 1131
Content-Type: text/xml
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: ro
Host: localhost
mymethod: urn:http://www.wsnamespace.com/myservice

SOAPAction: " http://www.wsnamespace.com/myservice/mymethod", , . "mymethod" - [WebMethod], " http://www.wsnamespace.com/myservice" - -, . (NuSOAP PHP,.NET, Java ..).

+3
5

Request.ContentType, , ,

application/soap+xml; charset=utf-8

, utf-8 .

, , URL-, -, , .

+2

- . , HTTP-, 80. , 80 SOAP/SOA .

IMAO, () - , , , .

0

​​, , HTTP. , , , SOAP - ...

<soap:Envelope xmlns:soap="..." soap:encodingStyle="...">

         IBM    

0

Have you tested System.Web.HttpContext.Current.Request.CurrentExecutionFilePathExtension ?? Usually it will be .asmx for webservices (json and xml), unless of course you process the service.

0
source

I use the following code to identify the type of request. Try this if it meets your requirement. Mark as an answer if it helps you.

if (request.Headers["SOAPAction"] != null || request.ContentType.StartsWith("application/soap+xml"))
    return ServiceRequestTypes.SoapRequest;
else if ("POST".Equals(request.RequestType, StringComparison.InvariantCultureIgnoreCase) && request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.InvariantCultureIgnoreCase))
    return ServiceRequestTypes.HttpPostRequest;
else if ("POST".Equals(request.RequestType, StringComparison.InvariantCultureIgnoreCase) && request.ContentType.StartsWith("application/json", StringComparison.InvariantCultureIgnoreCase))
    return ServiceRequestTypes.AjaxScriptServiceRequest;
return ServiceRequestTypes.Unknown;
0
source

Source: https://habr.com/ru/post/1729377/


All Articles