我将所有服务契约和数据契约都放在一个单独的类库项目中,以便它可以被 WCF 项目和 WPF 项目引用:
在添加对 WCF 服务的服务引用时,我确实将 Visual Studio 配置为重用所有引用的程序集,其中包括 Contract 项目:
生成过程失败并出现警告和错误:
Warning 1 The 'bindingConfiguration' attribute is invalid - The value 'BasicHttpBinding_IDataService' is invalid according to its datatype 'serviceBindingConfigurationType' - The Enumeration constraint failed. C:\..\App\App.Workflow\App.config 16 39 App.Workflow
Warning 2 The 'contract' attribute is invalid - The value 'IDataService' is invalid according to its datatype 'clientContractType' - The Enumeration constraint failed. C:\..\App\App.Workflow\App.config 16 80 App.Workflow
Error 3 Custom tool error: 'Reference.cs' : An assembly with the same simple name '.. Contract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side. C:\..\App\App.Workflow\Service References\DataServiceReference\Reference.svcmap 1 1 App.Workflow
生成将重用类库中定义的类型而不是重新生成的客户端类的正确方法是什么?
更新
我的配置文件:
工作流应用程序配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDataService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:54519/DataService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDataService" contract="IDataService"
name="BasicHttpBinding_IDataService" />
</client>
</system.serviceModel>
</configuration>
最佳答案
改变这个:
contract="IDataService"name="BasicHttpBinding_IDataService"
到
contract ="App.Contract.IDataService" name="BasicHttpBinding_contract". –
关于c# - 无法使用 "reusing types from referenced assemblies"选项生成 WCF 客户端类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29293181/