我在我的解决方案中创建了一个 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 类。那么这意味着什么呢?而且为什么会突然出现呢?请记住:我什至没有改变任何东西!
现在,这个问题的解决方案找到了here http://www.marcusoft.net/2009/01/custom-tool-warning-cannot-import.html,但没有解释这意味着什么。所以;在服务的“配置服务引用”中,取消选中“重用引用的程序集中的类型”复选框。现在重建一切正常,没有问题。但我真正改变了什么?这会对我的申请产生影响吗?什么时候应该取消选中此选项?我确实想重用已设置 DataContract 的类型,但仅此而已。如果没有经过此检查,我仍然可以访问那些内容吗?