views:

263

answers:

4

I want to use typed parameters in the web methods. But when visual studio 2005 creates the web reference on for the client it automatically creates it's own types. I am using a .net web service and a .net client.

For example:

< WebMethod > _ Public Function Foo() as ServerNamespace.Bar ... End Function

at the client the method becomes WebServiceInstance.Foo() as ClientNamespace.Webservice.Bar

returning a different type.

I started writing my own serialization helper class to convert the type, but I would have thought there would be a better way....

A: 

I've asked the same question before, so the answers I got might be of help:

http://stackoverflow.com/questions/216884/force-net-webservice-to-use-local-object-class-not-proxy-class

rwmnau
+3  A: 

If you can upgrade to .Net 3.0, I would suggest switching to WCF for your client proxy. Svcutil.exe is the tool to generate a WCF client proxy from the web service; it has an option /reference, which takes an assembly and reuses any shared types from it. (I would also suggest switchnig the service to WCF if it's under your control :-))

If you can't upgrade, wsdl.exe has an option /sharetypes which might help you, although I am not sure how to do it exactly.

Franci Penov
A: 

There is also a good answer here: http://stackoverflow.com/questions/127395/net-soap-common-types

Basically you are not supposed to share the data structures between the server and the client. But if you really want to there seam to be possibilities.

Torbjørn
A: 

I have upgraded to VS 2008, and WCF. I still find the solution to be half baked. Shared types seem to work ok as long as they are not typed collections, which get converted to and array or List(Of T).

I really don't understand what is so hard about serializing to and from the same object type, collection or otherwise.

A number of people reference this article from Code Project (article)

Which works for some objects, but for my data objects generates the following warnings (if I force it to use the DataContractSerializer):

Warning: The optional WSDL extension element 'body' from namespace 'http://schem as.xmlsoap.org/wsdl/soap12/' was not handled. XPath: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@ name='WSHttpBinding_IService']/wsdl:operation[@name='GetData']/wsdl:output

I could not find anything meaningful that would help me to debug this.

ptutt