构造函数WCF [英] Constructor in wcf

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

问题描述

任何一个可以告诉我如何创建WCF.I Datacontract的对象有哪些,我需要一个构造函数,但在客户端,当我创建一个对象的应用程序,它不显示constructor.I知道像一个解决方案添加一个部分类containg constructors.the困惑在这里,其中增加的部分类

Can any one just tell me how to create a object of Datacontract in WCF.I have a application in which i need a constructor but at client side when i create a object ,it doesnt shows a constructor.I know one solution like add a partial class containg constructors.the confusion is here "where to add a partial class"

请别人帮我........我是新来C#和.NET。

Please someone help me ........I am new to C# and .net.

推荐答案

有两种方式来完成给人一种DataContract类的构造函数。也许最一致的方式是将DataContract移动到你在你的服务和客户端引用一个单独的类库。正如约翰·桑德斯说,有一种方法生成用于引用的服务代理代码时告诉Visual Studio中使用现有的类。在此之后,你可以再补充构造函数该类正常。

There are two ways to accomplish giving a DataContract class a constructor. Probably the most consistent way is to move the DataContract into a separate class library which you reference in your service and client. As stated by John Saunders there is a way to tell Visual Studio to use an existing class when generating the proxy code for the referenced service. After this you can just add the constructor to that class normally.

如果你想构造函数只出现在客户端或某些其他原因无法使用共享类库,你可以创建一个部分类。真的是有这样一类没有明确的位置。所有这一切都需要通过部分类,它提供的构造函数来创建一个新的类文件,该文件相同的类定义为您的代理。

If you want the constructor to only appear on the client side or for some other reason are unable to use a shared class library, you can create a partial class. There is really no defined 'location' for such a class. All that is required for providing the constructor through a partial class is to create a new class file which defines the same class as your proxy.

所以,假设你有一个代理类ReferencedServiceProxy.ContractClass你需要创建一个新的代码文件定义了部分类

So assuming you have a proxy class ReferencedServiceProxy.ContractClass you need to create a new code file which defines the partial class

namespace ReferencedServiceProxy
{
   partial class ContractClass
   {
       // Constructor. Naturally the constructor cannot overwrite one
       // defined in the proxy class already. Not sure if those define
       // a default constructor.
       public ContractClass()
       {
           // Implementation
       }
   }
}

只要文件通常编译时,编译器的所有其余部分。

As long as the file is compiled normally, the compiler does all the rest.

然而,在不知道需要一个构造函数,它可能是值得指出的是,在客户端反序列化对象时为对象不是'建造'这样一个构造函数没有被调用。

However, without knowing the need for a constructor, it's probably worth pointing out that a constructor is not called when deserializing the object on client-side as the object is not 'constructed' as such.

http://mehranikoo.net/CS/archive/2007/11/09/DataContractConstructorsInWCF.aspx 具有与反序列化,以及如何影响它时会发生什么事。只是一些东西,我学到了艰辛的方式..使用Silverlight这竟然不支持的OnDeserialization属性。

http://mehranikoo.net/CS/archive/2007/11/09/DataContractConstructorsInWCF.aspx has something related to what happens during deserialization and how to affect it. Just something which I learned the hard way.. with silverlight which doesn't even support the OnDeserialization attribute.

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

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