简体   繁体   English

在C#中执行Web服务后如何捕获SOAP响应? 我需要在代码中进行操作

[英]How can I capture the SOAP response after executing a webservice in C#? I need to manipulate it in code

It is a foreign AXIS webservice and I am using "add service reference" in VS 2010 using C#. 这是国外AXIS网络服务,我正在使用C#在VS 2010中使用“添加服务参考”。 After executing a webmethod I can see the desired string I want to access in Fiddler. 执行完网络方法后,我可以在Fiddler中看到想要访问的字符串。 However, the place in the object returned to me where that string should go reads "null". 但是,该对象应返回给我的位置该字符串应为“ null”。

There are a few ways to go about this. 有几种方法可以解决此问题。

First, you don't have to use what "Add Service Reference" returns to you. 首先,您不必使用“添加服务参考”返回给您的内容。 If you look at Reference.cs , you will see that the proxy/contract are code constructs you can create yourself. 如果查看Reference.cs ,您将看到代理/合约是可以创建自己的代码构造。

If you go this route, then I would make sure you craft the classes that are used as return values yourself, applying the DataContract and DataMember attributes appropriately to serialize the result properly. 如果走这条路线,那么我将确保您自己制作用作返回值的类,并适当地应用DataContractDataMember属性以正确地序列化结果。

You can also check the what the IExtensibleDataObject implementation on the class that is generated by "Add Service Reference" returns. 您还可以检查“添加服务引用”生成的类的IExtensibleDataObject实现返回什么。 It's very possible the data you are looking for lies in there. 您正在寻找的数据很有可能位于其中。

Finally, if neither of these works for you and you want to deal with the raw message that is returned to your client, you can define your own contracts, as specified above, set the return value to the Message class and manipulate it yourself after the call completes. 最后,如果这两种方法都不适合您,并且您想处理返回给客户的原始消息,则可以定义自己的合同,如上面所指定的,将返回值设置为Message类,并在操作后自行处理通话完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM