PRB: The Proxy Class Has the First "out" Parameter of a Web Service Method That Returns "void" as a Return Value When You Add a Web Reference (322624)



The information in this article applies to:

  • Microsoft Web Services (included with the .NET Framework 1.1)
  • Microsoft Web Services (included with the .NET Framework) 1.0

This article was previously published under Q322624

SYMPTOMS

You can create a Web service that contains a Web service method that has at least one out parameter and that returns void. When you add a Web reference to this Web service, Microsoft Visual Studio .NET creates a proxy class with the first out parameter of the Web service method as a return value.

CAUSE

When you add a Web reference to a Web service, Visual Studio .NET internally runs the Web Services Discovery Tool (Disco.exe) to generate the corresponding Web Services Description Language (WSDL) code. Next, Visual Studio .NET internally runs the Web Services Description Language Tool (Wsdl.exe) to create a proxy class.

WSDL does not differentiate between a return value for a Web service method and an out parameter for a Web service method. Therefore, when Disco.exe generates the WSDL code for a Web service method that has a return value, the code has a WebMethodNameResponse element that contains a child element. The child element that the WebMethodNameResponse element contains corresponds to the return value. Similarly, when Disco.exe generates WSDL code for a Web service method that has an out parameter, the code has a WebMethodNameResponse element that contains a child element. The child element that the WebMethodNameResponse element contains corresponds to the out parameter. This behavior occurs regardless of whether the Web service method has a return value.

Note WebMethodName is a placeholder for the name of your Web service method. For example, if the name of your Web service method is MyWebMethod, the WSDL code that Disco.exe generates has a MyWebMethodResponse element.

When Wsdl.exe creates the proxy class that corresponds to your Web service method, Wsdl.exe assumes that the first child element corresponds to the Web service method's return value. Therefore, when you add a Web reference to a Web service that contains a Web service method and the Web service method has at least one out parameter and returns void, the problem described in the "Symptoms" section of this article occurs.

Note The WSDL code that Disco.exe generates may also have WebMethodNameResponse elements that contain child elements. The child elements that the WebMethodNameResponse elements contain may correspond to ref parameters. However, because WSDL differentiates between out parameters and ref parameters, Disco.exe generates additional code for ref parameters. Therefore, the problem discussed in this article does not apply to ref parameters.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Visual Studio .NET.
  2. Create an ASP.NET Web Service project that is named OutParamService by using Microsoft Visual C# .NET.

    By default, the Service1.asmx file is created.
  3. On the View menu, click Code.
  4. In the Service1.asmx.cs file, locate the following code:
          // WEB SERVICE EXAMPLE
          // The HelloWorld() example service returns the string Hello World
          //To build, uncomment the following lines then save and build the project
          // To test this Web service, press F5.
    
    //    [WebMethod]
    //    public string HelloWorld()
    //    {
    //       return "Hello World";
    //    }
  5. Replace the code that you located in step 4 with the following code:
    // OutParamMethod is a Web service method that has two out parameters and that returns void.
    [WebMethod]
    public void OutParamMethod(out int firstOutParam, out string secondOutParam)
    {
       firstOutParam = 1;
       secondOutParam = "secondOutParam";
    }
  6. On the Build menu, click Build OutParamService.
  7. On the Debug menu, click Start to run OutParamService.

    Service1 appears in your default Web browser. Notice the URL of Service1.
  8. Add a new Console Application project to your solution by using Visual C# .NET or by using Microsoft Visual Basic .NET.
  9. On the Project menu, click Add Web Reference.

    The Add Web Reference dialog box is displayed.
  10. If you are using Microsoft Visual Studio .NET 2003, type the URL from step 7 in the URL combo box, and then click Go.

    If you are using Microsoft Visual Studio .NET 2002, type the URL from step 7 in the Address combo box, and then click Go to.
  11. After Visual Studio .NET locates Service1, click Add Reference.

    A Web reference that is named localhost is added to your project.
  12. In Solution Explorer, click Show All Files.
  13. Under the Web References folder, expand the localhost Web reference.
  14. Under the localhost Web reference, expand the Reference.map node.
  15. If you are using Visual C# .NET, click the Reference.cs file under the Reference.map node.

    If you are using Visual Basic .NET, click the Reference.vb file under the Reference.map node.
  16. On the View menu, click Code.
  17. If you are using Visual C# .NET, locate the following code in the Reference.cs file:
    public int OutParamMethod(out string secondOutParam) {
       object[] results = this.Invoke("OutParamMethod", new object[0]);
       secondOutParam = ((string)(results[1]));
       return ((int)(results[0]));
    }
    OutParamMethod returns an int data type. The int data type corresponds to the first out parameter of the OutParamService Web service's OutParamMethod Web service method.

    If you are using Visual Basic .NET, locate the following code in the Reference.vb file:
    Public Function OutParamMethod(ByRef secondOutParam As String) As <System.Xml.Serialization.XmlElementAttribute("firstOutParam")> Integer
       Dim results() As Object = Me.Invoke("OutParamMethod", New Object(-1) {})
       secondOutParam = CType(results(1),String)
       Return CType(results(0),Integer)
    End Function
    OutParamMethod returns an Integer data type. The Integer data type corresponds to the first out parameter of the OutParamService Web service's OutParamMethod Web service method.

Modification Type:MajorLast Reviewed:9/29/2003
Keywords:kbXML kbIDEProject kbDiscovery kbMiscTools kbProxyDev kbWebServices kbClient kbProgramming kbprb KB322624 kbAudDeveloper