4

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.

  • 2
    Web services do not have "out parameters", nor parameters as such. Even more specifically for SOAP web services (which aren't the only kind out there), you have request and response XML. Parts of response XML _may_ be mapped to out-parameters on some platforms, but it's hard to be more specific than that unless you provide more details for your environment. – Pavel Minaev Oct 19 '09 at 17:31

3 Answers3

14

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.

GBegen
  • 6,107
  • 3
  • 31
  • 52
6

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.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
1

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

See Wikipedia

Gord
  • 1,805
  • 3
  • 17
  • 22