无需 wsdl 即可调用 Web 服务并反序列化 Soap
我有一个供应商似乎没有 wsdl 或者不愿意或不知道如何提供它。他们有许多 Web 服务(从技术上讲,它们是返回肥皂消息的 JSP),我需要使用其中大约 10-15 个来完成我的工作。
由于没有 WSDL,我无法使用“添加 Web 引用”功能来生成代理类等。我已经通过使用 WebClient
进行调用并将响应作为字符串返回来解决了这个问题,但现在我需要将响应反序列化到客户端类中。
我已经创建了 C# 类来匹配返回的 xml,但我不确定如何从 SOAP 反序列化,因为有太多 xml 噪音。我可以剥离 SOAP 信封标签,然后使用 XML 序列化程序反序列化为 List
,但这看起来确实很脏。有更好的方法吗?
I have a vendor who doesn't seem to have a wsdl or is unwilling or doesn't know how to provide it. They have a number of web services (technically they are JSPs that return soap messages) and I need to use about 10-15 of these to get my stuff done.
Since there isn't a WSDL, I can't use the 'add web reference' functionality to generate proxy classes and such. I've gotten around this by using WebClient
to make the calls and return the response as a string, but now I need to deserialize the response into client classes.
I've already made c# classes to match the xml that's returned, but I'm not sure how to deserialize from SOAP since there's so much xml noise. I could strip the SOAP envelope tags and then use the XML serializer to deserialize to a List<SomeType>
, but that seems really dirty. Is there a nicer way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发表了一篇文章,详细介绍了如何反序列化复杂的 xml。
这是链接:http://blog.impact-works.com/2011/06/30/how-to-serializedeserialize-complex-xml-in-asp-net-c/
希望有帮助
i published an article detailing on how to deserialize a complex xml.
here is the link : http://blog.impact-works.com/2011/06/30/how-to-serializedeserialize-complex-xml-in-asp-net-c/
hope it helps
您是否尝试过使用 SoapFormatter.Deserialize() 来反序列化响应。如果是这样,这会很有帮助。
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.deserialize(v=vs.71).aspx
Have you tried using SoapFormatter.Deserialize() for deserializing the response. If so, this would be helpful.
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter.deserialize(v=vs.71).aspx