最佳答案
我在我的解决方案中创建了一个 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 ..
I find this all confusing.. I don't have a Patient class on the client side Dashboard except the one I got through the service reference. So what does it mean? And why does it suddenly show? Remember: I didn't even change anything!
现在,解决这个问题的方法是找到 给你,但是没有解释这意味着什么。因此,在服务的“配置服务引用”中,我取消选中“重用类型在被引用的程序集中”复选框。现在重建工作一切顺利,没有问题。但我到底改变了什么?这会对我的申请产生影响吗?什么时候应该取消检查呢?我确实希望重用已经设置了 DataContracton 的类型,但仅此而已。不检查这个,我还能拿到吗?