引用WebService,带有参数的类构造函数 [英] Referenced WebService, class constructor with parameters

查看:225
本文介绍了引用WebService,带有参数的类构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有在C#ClassLibrary项目中引用的WebService。



在WebService中project我有一个名为User的类,它有两个构造函数 - 一个没有参数和一个whith参数。



当我尝试在ClassLibrary中从WS创建User类的实例时,我只能使用带参数的构造函数。



我的问题是,如何在构造函数中使用用户u =新用户等参数? some@email.com,...);



有什么想法吗? Thansk

Hi,

I have WebService which is referenced in C# ClassLibrary project.

In WebService project I have a class named User, which has two constructors - one without parameters and one whith parameters.

When I try to create instance of User class from WS in ClassLibrary, I can use only constructor with parameters.

My question is, how can I use in constructor with parameters like User u = new User("some@email.com", ...);.

Any idea? Thansk

推荐答案

不幸的是, Web服务引用代理类(当您添加对a的引用时生成Web服务)没有任何构造函数,即使原始类在服务端有。



如果你真的想使用构造函数,请转到类生成的代理类的定义并添加您需要的构造函数(您可以在服务端复制原始类的构造函数代码)



问题是,每次更新引用时,您的代理类都将被覆盖,您将丢失构造函数代码。



要克服此限制,您可以使用代理类,而不是修改代理类在包含构造函数的客户端项目中为 User 类编写一个部分类。在这种情况下,即使代理类被覆盖,部分类仍将保持不变,您将始终能够使用构造函数。



祝您好运:)
Unfortunately, the Web service reference proxy class (That is generated when you add a reference to a web service) does not have any Constructor, even if the original class have at the service-end.

If you really want to use a constructor, go to the Class definition of the proxy class that is generated and add the constructor that you require (You can copy the constructor code from the original class at service-end)

Problem is, every time you update reference, your proxy class will be overwritten and you will lose your constructor code.

To overcome this limitation, instead of modifying the proxy class, you can write a partial class for User class in your client project that will contain the constructor. In this case, even if the proxy class is overwritten, the partial class will remain intact and you will always be able to use the constructor.

Best of luck :)


asdfasdfasdf

asdfasdfasdf
Mubahil


这篇关于引用WebService,带有参数的类构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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