在ASP.NET Web服务中获取SOAP回复
我创建了一个SOAP Web服务来接收请求。我想用信封记录SOAP消息。 我发现了如何获取请求消息,但没有发现如何获取回复消息 为了获得XML请求,我使用下面的代码在ASP.NET Web服务中获取SOAP回复,soap,webmethod,Soap,Webmethod,我创建了一个SOAP Web服务来接收请求。我想用信封记录SOAP消息。 我发现了如何获取请求消息,但没有发现如何获取回复消息 为了获得XML请求,我使用下面的代码 // Create array for holding request in bytes byte[] inputStream = new byte[HttpContext.Current.Request.ContentLength]; // Read the entire request input stream HttpCon
// 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 XML。我需要一种方法来获取我的web方法向调用方重播的反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;
}
当你说你不能让它工作时,发生了什么?执行时inputStream的值是多少?谢谢您的帮助。我发布了更多的细节。