【问题标题】:Get SOAP Reply in ASP.NET Webservice在 ASP.NET Web 服务中获取 SOAP 回复
【发布时间】:2019-11-27 23:08:35
【问题描述】:

我创建了一个 SOAP WebService 来接收请求。我想用信封记录 SOAP 消息。 我发现了如何获取请求消息,但我没有发现如何获取回复消息。

为了获取 XML 请求,我使用下面的代码。

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

为了得到回复,我尝试在 Dispose 方法中执行此操作,但无法使其工作。

【问题讨论】:

  • 当你说你不能让它工作时,发生了什么? inputStream 执行时的值是多少?
  • 感谢您的尝试帮助。我发布了更多详细信息。

标签: soap webmethod


【解决方案1】:

InputStream 工作正常。 我得到了正确的请求 SOAP XML。我需要一种方法来获取我的 web 方法重播给调用者的 de SOAP XML。进入 WebMethod 的响应是不完整的。所以我尝试使用 Dispose 方法,但我遇到了同样的问题。 dispose 方法是在 .Net Framework 向调用者返回回复之前调用的。 我需要一种方法来记录 SOAP XML 请求和 SOAP XML 重播。

下面的代码可以很好地获取 XML 请求:

[WebMethod]
public ActivityCCPResponseOutput Request(ActivityCCPRequestInput ActivityCCPRequestInput)
{
    XmlDocument xmlSoapRequest = new XmlDocument();
    Stream receiveStream = HttpContext.Current.Request.InputStream;
    receiveStream.Position = 0;
    StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
    xmlSoapRequest.Load(readStream);

    string xmlSOAPRequest = xmlSoapRequest.InnerXml;

   ...
}

在下面的代码中,我无法得到回复。可能有不同的方法可以做到这一点。

void IDisposable.Dispose()
{
    XmlDocument xmlSoapResponse = new XmlDocument();

    // In this point HttpContext.Current.Response.OutputStream is empty
    Stream responseStream = HttpContext.Current.Response.OutputStream;

    responseStream.Position = 0;
    StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
    xmlSoapResponse.Load(readStream);

    string xmlSOAPReply = xmlSoapResponse.InnerXml;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 2013-03-18
    • 2011-02-07
    相关资源
    最近更新 更多