如何让网络服务序列化/反序列化 .net 中的相同类型 [英] How to get a webserice to serialize/deserialize the same type in .net

查看:30
本文介绍了如何让网络服务序列化/反序列化 .net 中的相同类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Web 方法中使用类型化参数.但是,当 Visual Studio 2005 为客户端创建 Web 引用时,它会自动创建自己的类型.我正在使用 .net 网络服务和 .net 客户端.

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.

例如:

<网络方法 > _公共函数 Foo() 作为 ServerNamespace.Bar...结束函数

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

在客户端,方法变为WebServiceInstance.Foo() 作为 ClientNamespace.Webservice.Bar

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

返回不同的类型.

我开始编写自己的序列化助手类来转换类型,但我认为会有更好的方法......

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

推荐答案

如果您可以升级到 .Net 3.0,我建议您的客户端代理切换到 WCF.Svcutil.exe 是从 Web 服务生成 WCF 客户端代理的工具;它有一个选项/reference,它接受一个程序集并重用其中的任何共享类型.(如果它在您的控制之下,我还建议将服务切换到 WCF :-))

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 :-))

如果您无法升级,wsdl.exe 有一个选项/sharetypes 可能会对您有所帮助,尽管我不知道具体如何去做.

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.

这篇关于如何让网络服务序列化/反序列化 .net 中的相同类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆