BUG: "InvalidOperationException" error message occurs when you consume a Web Service with an Out parameter (815211)
The information in this article applies to:
- Microsoft Web Services (included with the .NET Framework) 1.0
- Microsoft Web Services (included with the .NET Framework 1.1)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
SYMPTOMS You can use Visual C# .NET to create a Web Service that has
a Web Service method with an Out parameter. The Out parameter may appear before the In parameter or the Ref parameter. You must specify the SoapRpcMethodAttribute to the Web Service method to preserve the order of the parameters. The problem
occurs when you subsequently use this Web service that you created in Visual C#
.NET in a Visual Basic .NET application. You may receive the following error
message when you call the Web Service method. An unhandled exception of
type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There was an error generating the XML
document. CAUSEIf the Web Service method has an Out parameter, and you generate the proxy by using Visual Basic .NET,
then the Out parameter is generated as a ByRef parameter. This occurs because Visual Basic .NET does not support
Out parameters. The reflection code cannot differentiate between a
real ByRef parameter and a ByRef parameter that corresponds to an Out parameter. In the proxy class, the actual call to the Web service
is completed by using the Invoke method. In the Invoke method call, the Out parameter is missing. However, the generated serializer expects
the parameter. Therefore, you receive the error.RESOLUTIONTo resolve this problem, you can pass some dummy values for
the ByRef parameters that correspond to the out parameters. You can do this
in the Invoke method of the Web service proxy class. To do this, follow these
steps:
- Open the code for the Web service proxy file in Visual
Studio .NET. Or, you can use a text editor such as Notepad.
The Web
service proxy file is located in the Web References folder in the Web
Application directory. - Locate the Web Service method. Add the default values for the missing ByRef parameters to the parameters for the Invoke method.
For example, you can modify the proxy file that
is used in the sample code as follows: <System.Web.Services.Protocols.SoapRpcMethodAttribute("http://tempuri.org/SayHelloWorld", RequestNamespace:="http://tempuri.org/", ResponseNamespace:="http://tempuri.org/")> _
Public Function SayHelloWorld(ByRef sOutParam As String, ByVal iParam As Integer) As String
Dim results() As Object = Me.Invoke("SayHelloWorld", New Object() {Nothing, iParam})
sOutParam = CType(results(1),String)
Return CType(results(0),String)
End Function Note In the Invoke method parameters, you must initialize the object array with
{Nothing, iParam}, instead of only {iParam}.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCES For
additional information, click the following article number to view the article
in the Microsoft Knowledge Base: 309013
HOW TO: Create and Test an XML Web Service in Visual Basic .NET
Modification Type: | Minor | Last Reviewed: | 9/13/2005 |
---|
Keywords: | kbvs2002sp1sweep kbXML kbJIT kbDev kbClientProtocols kbProxyDev kbInetDev kbNameSpace kbProgramming kbbug KB815211 kbAudDeveloper |
---|
|