如何访问 SOAP 响应 [英] How do I get access to SOAP response

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

问题描述

(如果这里有什么需要澄清/更多细节,请告诉我.)

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

我有一个应用程序(C#、2.* 框架),它使用 SOAP 与第三方网络服务交互.我针对提供的 WSDL 使用 thinktecture 的 WSCF 插件来创建客户端实现.由于我无法控制的原因,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(以及扩展 Chris 的)解决方案.

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.

推荐答案

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

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).然后将预期的数据存储在某个地方供您自己使用,并且您还需要将旧流数据转发到新流以供 Web 服务后期使用数据,例如将 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.

示例从 MSDN 记录 Web 服务的所有流量

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

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