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

后端 未结 3 1399
醉酒成梦
醉酒成梦 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: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"
    
    
    
      
        
      
    
    

    And the response looks like this:

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

    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.

提交回复
热议问题