Is it unusual for a web service call to have an “out” parameter?

守給你的承諾、 提交于 2019-12-31 02:01:07

问题


Is it unusual for a web service call to have an "out" parameter? If so, why?

I am using C# web service and webserive consumer also will be c# app.


回答1:


If you are referring to out parameters at the C# level in an ASP.Net web service, I don't think its unusual at all. Your out parameters will simply become child elements of the response element. Here's a short example web service with a single web method that has out parameters:

[WebService(Namespace = "http://begen.name/xml/namespace/2009/10/samplewebservicev1")]
public class SampleWebServiceV1 : WebService
{
    [WebMethod]
    public void
    WebMethodWithOutParameters(out string OutParam1, out string OutParam2)
    {
        OutParam1 = "Hello";
        OutParam2 = "Web!";
    }
}

With the above web method, the SOAP request looks like this:

POST /SampleWebServiceV1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://begen.name/xml/namespace/2009/10/samplewebservicev1/WebMethodWithOutParameters"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebMethodWithOutParameters xmlns="http://begen.name/xml/namespace/2009/10/samplewebservicev1" />
  </soap:Body>
</soap:Envelope>

And the response looks like this:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebMethodWithOutParametersResponse xmlns="http://begen.name/xml/namespace/2009/10/samplewebservicev1">
      <OutParam1>Hello</OutParam1>
      <OutParam2>Web!</OutParam2>
    </WebMethodWithOutParametersResponse>
  </soap:Body>
</soap:Envelope>

Note: this doesn't invalidate the other answers to this question, as they were all considering this from the web service level, not the C# level.




回答2:


Yes, because a web service should be thought of as taking a message (request) and spitting out a result (output).

An 'out' parameter would indicate that you want to return a modified version of the original request message...which really doesn't make sense. If you need to have multiple outputs, you need to think about how to package those values in to a single response message.




回答3:


Yes, You would want to bundle what you return into a single object (typically a Response Object)

See Wikipedia



来源:https://stackoverflow.com/questions/1590002/is-it-unusual-for-a-web-service-call-to-have-an-out-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!