我在我的解决方案中创建了一个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,但没有解释这意味着什么。因此,在服务的“配置服务引用”中,我取消选中“在引用的程序集中重用类型”复选框。重建现在一切正常,没有问题。但是我到底改变了什么呢?这会对我的应用程序产生影响吗?什么时候应该取消勾选呢?我确实想重用我在其上设置了DataContract的类型,但仅此而已。在没有检查的情况下,我还能访问那些吗?
发布于 2011-05-13 03:30:29
今天我也遇到了这个问题。我花了整整一天的时间才找到我的错误。希望能有所帮助。
我的无法导入的类有一个cutom枚举类型属性。此属性标记为DataMember,枚举也标记为DataContract。到目前为止一切都很好。我只是忘了把每个枚举成员都标记为EnumMember。
所以我改变了
[DataContract]
public enum SortMethodType
{
Default = 0,
Popularity = 1,
ReleaseDate = 2,
PublishedDate = 3,
TranslatedTitle = 4,
OriginalTitle = 5,
UserRating = 6,
Duration = 7
}
要这样做:
[DataContract]
public enum SortMethodType
{
[EnumMember]
Default = 0,
[EnumMember]
Popularity = 1,
[EnumMember]
ReleaseDate = 2,
[EnumMember]
PublishedDate = 3,
[EnumMember]
TranslatedTitle = 4,
[EnumMember]
OriginalTitle = 5,
[EnumMember]
UserRating = 6,
[EnumMember]
Duration = 7
}
它终于成功了!
发布于 2010-03-17 02:59:24
在添加引用时转到高级属性,并从检查表中删除"System.Window.Browser“,这就解决了问题。
发布于 2011-12-04 02:24:56
这听起来可能很奇怪,但我通过删除引用,然后关闭Visual Studio,然后重新打开它,最后再次添加引用来修复它。
我认为定制工具之类的东西需要重新启动。
https://stackoverflow.com/questions/1872865
复制相似问题