无需 wsdl 即可调用 Web 服务并反序列化 Soap

发布于 2024-12-03 12:12:57 字数 375 浏览 3 评论 0原文

我有一个供应商似乎没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悍妇囚夫 2024-12-10 12:12:57

我发表了一篇文章,详细介绍了如何反序列化复杂的 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

·深蓝 2024-12-10 12:12:57

您是否尝试过使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文