简体   繁体   中英

Accept SOAP requst in ASP.NET Webservice

I'm trying to receive a SOAP request on an ASP.NET webservice but I'm stucking here right now.

The first thing I tried was to just receive a simple string in my webservice but my webservice denied that request, because it was a "dangerous request". The second thing I tried was to use XmlDocument and XElement as input date type but when I try that I get an IndexOutOfRangeException in SoapUI and can't call that method simply in the browser.

Is there any trick to accept SOAP requests in the WebMethod?

To make it easier to understand, I'm looking for a solution like that:

[WebMethod]
public XmlDocument Method(string soapRequest)
{
    XmlDocument xmlAnswer = doSomethingWithRequest(soapRequest);

    return xmlAnswer;
}

Unfortunately I couldn't find any way to do it with such a simple solution like I asked for. I tried XmlElement how it is mentioned in this (very old) article .

I did it now in that way:

// Create array for holding request in bytes
byte[] inputStream = new byte[HttpContext.Current.Request.ContentLength];

// Read the entire request input stream
HttpContext.Current.Request.InputStream.Read(inputStream, 0, inputStream.Length);

// Set stream position back to beginning
HttpContext.Current.Request.InputStream.Position = 0;

// Get the XML request
string xmlRequestString = Encoding.UTF8.GetString(inputStream);

And that works fine for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM