简体   繁体   English

接受ASP.NET Web服务中的SOAP请求

[英]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. 我正在尝试在ASP.NET Web服务上接收SOAP请求,但我现在停留在这里。

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". 我尝试做的第一件事是在Web服务中只收到一个简单的字符串,但是我的Web服务拒绝了该请求,因为这是一个“危险的请求”。 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. 我尝试的第二件事是使用XmlDocument和XElement作为输入日期类型,但是当我尝试在SoapUI中获得IndexOutOfRangeException时,不能仅仅在浏览器中调用该方法。

Is there any trick to accept SOAP requests in the WebMethod? 在WebMethod中是否有任何技巧可以接受SOAP请求?

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 . 我尝试了XmlElement在这篇(很旧的) 文章中是如何提到的。

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. 这对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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