【问题标题】:Accept SOAP requst in ASP.NET Webservice在 ASP.NET Web 服务中接受 SOAP 请求
【发布时间】:2016-11-29 16:23:16
【问题描述】:

我正在尝试在 ASP.NET 网络服务上接收 SOAP 请求,但我现在卡在这里。

我尝试的第一件事是在我的网络服务中接收一个简单的字符串,但我的网络服务拒绝了该请求,因为这是一个“危险的请求”。 我尝试的第二件事是使用 XmlDocument 和 XElement 作为输入日期类型,但是当我尝试在 SoapUI 中得到一个 IndexOutOfRangeException 并且不能简单地在浏览器中调用该方法时。

在 WebMethod 中接受 SOAP 请求有什么技巧吗?

为了更容易理解,我正在寻找这样的解决方案:

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

    return xmlAnswer;
}

【问题讨论】:

    标签: c# asp.net web-services soap


    【解决方案1】:

    不幸的是,我找不到任何方法来使用我要求的如此简单的解决方案。我试过XmlElement在这个(很老的)article中是如何提到的。

    我现在以that 方式做到了:

    // 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);
    

    这对我来说很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-07
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多