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

后端 未结 3 1378
醉酒成梦
醉酒成梦 2021-01-20 04:58

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.

相关标签:
3条回答
  • 2021-01-20 05:14

    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.

    0 讨论(0)
  • 2021-01-20 05:17

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

    See Wikipedia

    0 讨论(0)
  • 2021-01-20 05:33

    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.

    0 讨论(0)
提交回复
热议问题