为什么webservice返回的值不是xml

发布于 2024-11-08 04:09:02 字数 351 浏览 0 评论 0原文

webservice.PService pService = new Project.webservice.PService();
var v3 = passportService.HelloWorld();
Response.Write(v3);

我调试了一下,发现v3是字符串。为什么? webservcie 不应该总是返回 xml 吗? 网络服务是:

[WebMethod]
public string HelloWorld()
{
    return "Hello World";
}

编辑: 如果我想要 webservcie 返回一个对象或对象列表怎么办?

webservice.PService pService = new Project.webservice.PService();
var v3 = passportService.HelloWorld();
Response.Write(v3);

I debugged it and found that v3 was string. Why? Should not a webservcie always return xml?
The webservice was:

[WebMethod]
public string HelloWorld()
{
    return "Hello World";
}

Edit:
What if I want an object or a list of objects to be returned by the webservcie?

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

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

发布评论

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

评论(2

小耗子 2024-11-15 04:09:02

我建议您可能要从 Microsoft。

然后查看返回对象

虽然 Web 服务传输层使用 XML,但其中有大量您的应用程序代码通常不会关心的内容,这就是为什么客户端代理会为您将其全部剥离,以便您留下您感兴趣的位。

只要您想要从 WebMethod 返回的对象是可序列化的,您就应该能够将其定义为返回类型,并且它将被编码为你。当您生成客户端代理时,将为要反序列化的请求创建一个类似的对象。

WebMethod 返回对象集合本质上是相同的,但值得注意的是 List 通过线路转换为数组

I suggest you might want to start with Microsoft.

Then have a look at returning objects.

Whilst the webservice transport layer uses XML, there's an awful lot of stuff in there that your application code typically isn't going to care about, which is why the client proxies strip it all out for you, so that you're left with the the bits that you're interested in.

As long as the object you want to return from your WebMethod is serializable, you should be able to just define it as a return type and it'll get encoded for you. When you generate the client side proxy, a similar object will be created for the request to be deserialized into.

Returning collections of objects from your WebMethod is essentially the same, although it's worth noting that List<T> is converted to an Array, over the wire.

夏尔 2024-11-15 04:09:02

Web 服务获取一个对象,将其序列化为 XML,然后将该 XML 发送回客户端。客户端/代理解析该 XML,并将其反序列化回对象。返回的类型由您的 Web 方法签名确定。如果您想查看原始 XML,可以通过检查 HTTP 消息来实现,但使用代理的目的是它为您进行转换。

The web service takes an object, and serialises it to XML, and sends that XML back to the client. The client/proxy parses that XML, and deserialises it back to an object. The type returned is determined by your web method signature. If you wanted to see the original XML, you could do so by inspecting the HTTP messages, but the point of using the proxy is that it does the conversion for you.

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