HOW TO: Change Types Used in Proxy Classes That Are Generated with Wsdl.exe

This article was previously published under Q326790
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
The Web Services Description Language tool (Wsdl.exe) generates proxy code for XML Web services. The generated types that are used in the proxy class are based on the contents of the WSDL document that describes the XML Web service. However, the generated types might not be what you want nor what you expect.

Wsdl.exe determines the best generated type to use for the objects that are specified in the service description. In some cases, the tool uses a least-common-denominator approach for casting objects to a type. For example, an ArrayList parameter in a WebMethod is described in WSDL as a XML Schema (XSD) sequence. When Wsdl.exe finds this array description in the service description, Wsdl.exe then generates a proxy class that uses an Object Array. You may prefer to work with an ArrayList, which was the original type that was used in the WebMethod. If you do not want to use the generated types, you can change the generated types to more desirable types. To get the appropriate object type, you can open the file that contains the generated proxy class, manually change the generated method parameter, and then return types to the appropriate object types.

back to the top

Generate the Proxy Code

In the following sample, the XML Web service has the Web Service method with the following prototype:
string DummyMethod(System.Collections.ArrayList intList)				
You can use Wsdl.exe to generate the proxy source file.

back to the top

Manually Modify the Code

  1. Open the proxy source file in a text editor.
  2. Find the two methods:
            public string DummyMethod(object[] intList) {            object[] results = this.Invoke("DummyMethod", new object[] {                        intList});            return ((string)(results[0]));        }        public System.IAsyncResult BeginDummyMethod(object[] intList, System.AsyncCallback callback, object asyncState) {            return this.BeginInvoke("DummyMethod", new object[] {                        intList}, callback, asyncState);        }					
  3. Modify the code to:
            public string DummyMethod(System.Collections.ArrayList intList) {            object[] results = this.Invoke("DummyMethod", new object[] {                        intList});            return ((string)(results[0]));        }        public System.IAsyncResult BeginDummyMethod(System.Collections.ArrayList intList, System.AsyncCallback callback, object asyncState) {            return this.BeginInvoke("DummyMethod", new object[] {                        intList}, callback, asyncState);        }					
back to the top

More Information

XML Web services serialize objects to XML and then deserialize the XML back to objects. Generally, an object of a particular type can be serialized and then deserialized to another object of the same type. However, if you use different types, this may not work.

back to the top

REFERENCES
For additional information about how types are serialized and deserialized, visit the following Microsoft Web site:

back to the top
Properties

Article ID: 326790 - Last Review: 12/07/2015 12:01:54 - Revision: 4.1

Microsoft Web Services (included with the .NET Framework) 1.0 , Microsoft Web Services Enhancements for Microsoft .NET 1.1

  • kbnosurvey kbarchive kbhowtomaster KB326790
Feedback