在ASP.NET Web服务中获取SOAP答复

问题描述 投票:0回答:1

我创建了一个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方法中,但无法使其正常工作。

soap webmethod
1个回答
0
投票

InputStream正常工作。我正确地获得了请求SOAP XML。我需要一种方法来获取我的Web方法重播给调用方的de SOAP XML。进入WebMethod的响应未完成。所以我尝试使用Dispose方法,但是我遇到了同样的问题。在.Net Framework将回复返回给调用方之前,将调用dispose方法。我需要一种方法来记录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;
}
© www.soinside.com 2019 - 2024. All rights reserved.