Mik*_*ras 5 wcf generated-code svcutil.exe
我正在使用SvcUtil.exe生成我的WCF代码,如下所示:
SvcUtil.exe http://www.MyServer.com:8080/MyService/mex /out:"C:\test.cs" /mc
Run Code Online (Sandbox Code Playgroud)
我可以让它工作,但如果我设置添加一个/namespace参数(/namespace:*,MyNamespace),它会覆盖生成的接口ConfigurationName生成的值ServiceContractAttribute:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="MyNamespace.MyServiceName")]
public interface MyServiceName
{ ... }
Run Code Online (Sandbox Code Playgroud)
如果我没有设置命名空间,则值为ConfigurationName"MyServiceName",这是正确的("MyNamespace.MyServiceName"不正确且不起作用).我已经尝试添加/ ServiceName:MyService参数,但它告诉我它说
错误:/ serviceName:选项与其他选项冲突.检查您对该工具的使用.
如何在不覆盖ConfigurationName的情况下为生成的类指定命名空间?
我有同样的问题.我有一个ServiceReference,它具有ConfigurationName ="MyWebService.MyWebServiceSoap",它是在通过VisualStudio.NET 2010添加时生成的.当我使用svcutil从msbuild生成同一个类时,svcutil想要将ConfigurationName设置为等于我设置的值用于命名空间.所以如果我像这样设置/ n属性:
/n:*,MyApplication.MyWebService.MyWebServiceSoap
Run Code Online (Sandbox Code Playgroud)
我为生成的类获取了正确的命名空间,但ConfigurationName也设置为MyApplication.MyWebService.MyWebServiceSoap.
这似乎表明VS.NET不使用svcutil,我发现有些帖子似乎也表明了这一点.
我希望我有一个更好的答案,但由于我正在使用来自MSBuild的svcutil,我的解决方案是让svcutil使用不正确的ConfigurationName生成类,然后使用FileUpdate任务使用正则表达式修改该名称.同样,它远非理想,但我在svcutil文档中看不到任何可以指定ConfigurationName的内容.
此外,值得一提的是serviceName选项用于从已编译的代码中导出元数据,它对于生成客户端代理类无效,这可能是您获得该serviceName选项冲突错误的原因.
请参阅:http://msdn.microsoft.com/en-us/library/aa347733.aspx