且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何才能获得SOAP响应

更新时间:2023-02-15 09:07:24

您可以利用。的SoapExtension从现有WSE2.0框架拦截来自服务器的响应

You can utilize SoapExtension from existing WSE2.0 framework to intercept the responses from the server.

public class MyClientSOAPExtension : SoapExtension
{

     Stream oldStream;
     Stream newStream;

     // Save the Stream representing the SOAP request or SOAP response into
     // a local memory buffer.
     public override Stream ChainStream( Stream stream )
     {
            oldStream = stream;
            newStream = new MemoryStream();
            return newStream;
     }

    public override void ProcessMessage(SoapMessage message)
    {
       switch (message.Stage)
        {
            case SoapMessageStage.BeforeDeserialize:
                // before the XML deserialized into object.
                break;
            case SoapMessageStage.AfterDeserialize:
                break;        
            case SoapMessageStage.BeforeSerialize:
                break;
            case SoapMessageStage.AfterSerialize:
                break;            
            default:
                throw new Exception("Invalid stage...");
        }       
    }
}

目前SoapMessageStage.BeforeDeserialize阶段,
你可以阅读你oldstream想要的预期数据(如使用的XmlReader)。 $ B $(2)然后存储所期望的数据的地方为自己使用,并且还需要
中的原有数据流的数据转发到方通后用于网络服务稍后阶段使用的数据,例如反序列化XML到对象中。

At stage of SoapMessageStage.BeforeDeserialize, You can read the expected data you want from oldstream (e.g. use XmlReader). Then store the expected data somewhere for yourself to use and also you need forward the old stream data to the newstream for web service later stage to use the data, e.g. deserialize XML into objects.

记录所有流量通过Web服务从MSDN