我在我的解决方案中创建了一个 WCF 服务库项目,并且有对此的服务引用。我使用类库中的服务,因此除了类库之外,我还有来自我的 WPF 应用程序项目的引用。服务是直接设置的 - 仅更改以获得异步服务功能。
一切正常 - 直到我想更新我的服务参考。它失败了,所以我最终回滚并重试,但即使那样它也失败了!所以 - 更新服务引用失败而不对其进行任何更改。为什么?!
我得到的错误是这个:
Custom tool error: Failed to generate code for the service reference
'MyServiceReference'. Please check other error and warning messages for details.
该警告提供了更多信息:
Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the
following types. Only matching types can be valid references:
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']
也有两个类似的警告说:
Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ISomeService']
同样适用于:
Custom tool warning: Cannot import wsdl:port ..
我觉得这一切都令人困惑。我在客户端仪表板上没有 Patient 类,除了我通过服务参考获得的那个。那么这是什么意思呢?为什么会突然出现?记住:我什至没有改变任何东西!
现在,在这里找到了解决方案,但没有解释这意味着什么。所以; 在服务的“配置服务引用”中,我取消选中“在引用的程序集中重用类型”复选框。现在重建一切正常,没有问题。但我真正改变了什么?这会对我的申请产生影响吗?什么时候应该取消选中这个?我确实想重用我设置了 DataContract 的类型,但没有更多。如果没有这个检查,我仍然可以访问那些吗?