How to get a webserice to serialize/deserialize the same type in .net

只愿长相守 提交于 2020-01-25 02:47:50

问题


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....


回答1:


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.




回答2:


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

Force .NET webservice to use local object class, not proxy class




回答3:


There is also a good answer here: .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.




回答4:


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.



来源:https://stackoverflow.com/questions/224474/how-to-get-a-webserice-to-serialize-deserialize-the-same-type-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!