WSDL Web 参考客户端和更改方法以返回肥皂字符串

发布于 2024-12-27 05:56:06 字数 1036 浏览 1 评论 0原文

首先,我在 WCF/WSDL 领域完全是菜鸟,所以请耐心等待我。

好吧,我有一个用于复杂消息类型的 WSDL、XSD,我在 C# 控制台应用程序中生成了一个测试客户端。我添加了对 WSDL 的 Web 引用,并在 Reference.cs 中生成了代码。

我调用了reference.cs中可用的方法,效果很好。我在 Reference.cs 中的方法上添加了肥皂跟踪扩展来记录肥皂请求/响应,工作正常。

在客户端中,我得到 WSDL 复杂类型类对象,在其中我看到同步和异步调用的所有内容都返回正常。

现在这就是我想要/尝试做的,我希望方法返回的不是反序列化的类对象,而是肥皂字符串,就像它们在流中和反序列化之前接收到的一样。

如何更改方法以返回肥皂字符串?这不是访问它们(我成功做到了),而是直接从方法返回。

请为我指出正确的方向,否则我必须去实现一个我试图避免的肥皂客户端。

我很感激任何帮助。让我知道我是否应该澄清一些事情。

更新:

好的,先生,这就是我所做的:

使用 svcutil 从 WSDL 生成一个类,然后:

ServiceClient1 sc1 = new ServiceClient1();
TestResponseClass trc1 = sc1.method1("Testinput");
System.Xml.Serialization.XmlSerializer x = new    System.Xml.Serialization.XmlSerializer(typeof(TestResponseClass ),"http://xxx.xxx.xxx.local/Service1.wsdl");
StringWriter stringWriter = new StringWriter();
x.Serialize(stringWriter, trc1);
Console.Write(stringWriter.ToString());  

这样我得到了 xml 响应。更接近我想要的,我会尝试将其转换为肥皂反应。我希望我现在走在正确的道路上。如果不对请指正。学习并且学习得很快......我想

First of all I am complete noob in WCF/WSDL area so please be patient with me

Okay, I have got a WSDL,XSD for complex message types, I generated a test client in C# console application. I added a web reference to WSDL got code generated in reference.cs.

I called methods available in reference.cs, fine works perfect. I added soap trace extension on methods in reference.cs to log soap requests/response, works fine.

In client I get WSDL complex type class object, where I see everything is returned fine for both sync and async calls.

Now this is what I want/trying to do, I want methods to return not deserialized class object but soap string, like they are received in stream and before deserialization.

How do I alter method to return soap string? It's not about accessing them(which I succceed to do) but to return directly from method.

Please point me in right direction else I have to go in implementing a soapclient, which I trying to avoid.

I appreciate any help. Let me know if I should clarify things.

Update:

Okay sir, this is what I did:

generated a class from WSDL using svcutil, then:

ServiceClient1 sc1 = new ServiceClient1();
TestResponseClass trc1 = sc1.method1("Testinput");
System.Xml.Serialization.XmlSerializer x = new    System.Xml.Serialization.XmlSerializer(typeof(TestResponseClass ),"http://xxx.xxx.xxx.local/Service1.wsdl");
StringWriter stringWriter = new StringWriter();
x.Serialize(stringWriter, trc1);
Console.Write(stringWriter.ToString());  

this way I got xml response. more close to what I was willing to have, I'll try to convert it to soap response. I hope I am on right track now. Please correct if not. learning and learning fast...I guess

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

口干舌燥 2025-01-03 05:56:06

您可能会有点困惑。不要使用网络参考。这是遗留的 ASMX 技术,已被 WCF 和“添加服务引用”所取代。

不要使用 ASMX 进行新开发。


我已经看到你的更新了,你确实很困惑。

你的代码有:

ServiceClient1 sc1 = new ServiceClient1();
TestResponseClass trc1 = sc1.method1("Testinput");

就是这样。你完成了。您已经向服务发送了 SOAP 消息并且已经收到了响应。根本不需要使用 XML。

You may be getting confused a bit. Do not use Web References. This is the legacy ASMX technology which has been replaced by WCF and "Add Service Reference".

Do not use ASMX for new development.


I have seen your update, and you are, indeed, confused.

Your code has:

ServiceClient1 sc1 = new ServiceClient1();
TestResponseClass trc1 = sc1.method1("Testinput");

That's it. You're done. You have already sent a SOAP message to the service and have already received the response. There is no need to work with XML, at all.

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