设置使用ContractNamespace属性WCF DataContract命名空间属性、空间、ContractNamespace、DataContract

由网友(眼裡有星星)分享简介:在设计我的服务,我决定,我想自定义出现在生成的WSDL的命名空间。In designing my service, I decided that I wanted to customize the namespaces that appeared in the resulting WSDL.对于DataContra...

在设计我的服务,我决定,我想自定义出现在生成的WSDL的命名空间。

In designing my service, I decided that I wanted to customize the namespaces that appeared in the resulting WSDL.

对于DataContracts,我遇到了 ContractNamespace 属性,它似乎是一个很好的快捷方式替代明确设置了相同的命名空间为每个DataContract。我最初的尝试是这样的:

For the DataContracts, i came across the ContractNamespace attribute which seemed a nice shortcut alternative to setting the same namespace explicitly for every DataContract. My initial attempt looked like this:

[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03")]
namespace MyCompany.MyContracts
{
    [DataContract]
    //...multiple datacontract classes here
}

要我吃惊的是,这没有奏效。经过一番摆弄,我是唯一成功的时候,我终于将 ClrNamespace 属性等于我的CLR命名空间(在本例中MyCompany.MyContracts)的财产。因此,像这样

To my surprise, this did not work. After much tinkering, I was only successful when I finally set the ClrNamespace property of the attribute equal to my CLR namespace (MyCompany.MyContracts in the example). So something like this

[assembly:ContractNamespace("http://types.mycompany.com/2010/08/03",
          ClrNamespace="MyCompany.MyContracts")]

我的问题是:为什么这不工作的第一种方式?我的预期是,不指定一个CLR namepsace,此属性将影响所有datacontracts组装范围。

My question is: why did this not work the first way? My expectation was that by not specifying a CLR namepsace, this attribute would affect all datacontracts assembly-wide.

推荐答案

如果我没有记错,如果 ClrNamespace 被省略,则合同的命名空间设置适用于全局命名空间中的对象。

If I'm not mistaken, if the ClrNamespace is ommitted, then the contract namespace setting applies to objects in the global namespace.

阅读全文

相关推荐

最新文章