Microsoft KB Archive/322624

= PRB: The Proxy Class Has the First &quot;out&quot; Parameter of a Web Service Method That Returns &quot;void&quot; as a Return Value When You Add a Web Reference =

Article ID: 322624

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Web Services Enhancements for Microsoft .NET 1.1
 * Microsoft Web Services Enhancements for Microsoft .NET 2.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  Response element that contains a child element. The child element that the  Response 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  Response element that contains a child element. The child element that the  Response element contains corresponds to the out parameter. This behavior occurs regardless of whether the Web service method has a return value.

Note  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 &quot;Symptoms&quot; section of this article occurs.

Note The WSDL code that Disco.exe generates may also have  Response elements that contain child elements. The child elements that the  Response 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.



Steps to Reproduce the Problem
 Start Visual Studio .NET. 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. On the View menu, click Code.  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 &quot;Hello World&quot;; //   }   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 = &quot;secondOutParam&quot;; } </li> On the Build menu, click Build OutParamService.</li> On the Debug menu, click Start to run OutParamService.

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

The Add Web Reference dialog box is displayed.</li> 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.</li> After Visual Studio .NET locates Service1, click Add Reference.

A Web reference that is named localhost is added to your project.</li> In Solution Explorer, click Show All Files.</li> Under the Web References folder, expand the localhost Web reference.</li> Under the localhost Web reference, expand the Reference.map node.</li> 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.</li> On the View menu, click Code.</li>  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(&quot;OutParamMethod&quot;, 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(&quot;firstOutParam&quot;)> Integer Dim results As Object = Me.Invoke(&quot;OutParamMethod&quot;, 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. </li></ol>

<div class="references_section">