Why the value webservice returns was not xml
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?
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.
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.
精彩评论