我如何才能获得SOAP响应 [英] How do I get access to SOAP response

查看:210
本文介绍了我如何才能获得SOAP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(如果有的话这里需要澄清/详细请让我知道。)

(If anything here needs clarification/ more detail please let me know.)

我有一个应用程序(C#,2 *框架),与第三接口三方Web服务使用SOAP。我用thinktecture的WSCF外接针对提供WSDL来创建客户端实现。我无法控制的原因,SOAP消息交换使用WSE2.0安全(的thinctecture实施不得不进行修改,包括WSE2.0引用)。除了正常的数据包我附加存储X509证书,并从以前的调用不同的Web服务的二进制安全令牌。我们正在使用某种形式的SSL加密 - 我不知道的细节。

I have an application (C#, 2.* framework) that interfaces with a third-party webservice using SOAP. I used thinktecture's WSCF add-in against a supplied WSDL to create the client-side implementation. For reasons beyond my control the SOAP message exchange uses WSE2.0 for security (the thinctecture implementation had to be modified to include the WSE2.0 reference). In addition to the 'normal' data package I attach a stored X509 cert and a binary security token from a previous call to a different web service. We are using SSL encryption of some sort - I don't know the details.

所有必需的序列化/反序列化包含在Web服务客户端 - 控制时,调用客户端包含在SOAP响应整个​​XML字符串后回到我的意思不能提供给我 - 只是反序列化组件。不要误会我的意思 - 我认为这是好事,因为这意味着我没有做我自己

All the necessary serialization/deserialization is contained in the web service client - meaning when control is returned to me after calling the client the entire XML string contained in the SOAP response is not available to me - just the deserialized components. Don't get me wrong - I think that's good because it means I don't have to do it myself.

不过,为了让我有一些值得存储/存档我有重新序列化的根元素中的数据。这似乎是对资源的浪费,因为我的结果是SOAP响应。

However, in order for me to have something worth storing/archiving I am having to re-serialize the data at the root element. This seems like a waste of resources since my result was in the SOAP response.

现在我的问题:
我如何才能访问到SOAP响应的清的版本,这样我就不必重新序列化家居的存储/归档

编辑 - 我的应用程序是运行作为网络服务的无形的Windows应用程序 - 由WebsphereMQ客户端触发触发监视器。我不的认为的ASP.NET解决方案将适用

Edit- My application is a 'formless' windows app running as a network service - triggered by a WebsphereMQ client trigger monitor. I don't think ASP.NET solutions will apply.

编辑 - 既然共识到目前为止,这不要紧,无论我应用程序是ASP.NET或没有,那么我会给CodeMelt的(通过扩展克里斯的)解决方案的一个镜头。

Edit - Since the consensus so far is that it doesn't matter whether my app is ASP.NET or not then I will give CodeMelt's (and by extension Chris's) solution a shot.

推荐答案

您可以利用。的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

这篇关于我如何才能获得SOAP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆