增加服务引用时出现错误 "无法导入wsdl:portType"。

7
我无法在VS 2010或2012中使用“添加服务引用”功能来构建基于ServiceStack的Web服务。我已经按照github上的指南进行操作,包括将ContractNameSpace属性添加到AssemblyInfo.cs文件中,并确保所有DTO都位于相同的命名空间中,但仍然没有成功。相反,我收到了一些构建警告和错误信息,如下所示。
有人能提出任何关于出现问题的建议吗?
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://schemas.servicestack.net/types' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:portType[@name='ISyncReply']

Warning 2 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://schemas.servicestack.net/types']/wsdl:portType[@name='ISyncReply']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_ISyncReply']

Warning 3 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_ISyncReply']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:service[@name='SyncReply']/wsdl:port[@name='WSHttpBinding_ISyncReply']

Warning 4 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://schemas.servicestack.net/types' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:portType[@name='IOneWay']

Warning 5 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://schemas.servicestack.net/types']/wsdl:portType[@name='IOneWay']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_IOneWay']

Warning 6 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_IOneWay']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:service[@name='AsyncOneWay']/wsdl:port[@name='WSHttpBinding_IOneWay']

Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://schemas.servicestack.net/types' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:portType[@name='ISyncReply']

Warning 2 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://schemas.servicestack.net/types']/wsdl:portType[@name='ISyncReply']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_ISyncReply']

Warning 3 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_ISyncReply']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:service[@name='SyncReply']/wsdl:port[@name='WSHttpBinding_ISyncReply']

Warning 4 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://schemas.servicestack.net/types' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:portType[@name='IOneWay']

Warning 5 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://schemas.servicestack.net/types']/wsdl:portType[@name='IOneWay']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_IOneWay']

Warning 6 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:binding[@name='WSHttpBinding_IOneWay']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.servicestack.net/types']/wsdl:service[@name='AsyncOneWay']/wsdl:port[@name='WSHttpBinding_IOneWay']

4
禁用“在服务引用配置中重用已引用程序集中的类型”是否有帮助? - Moofafa
欢迎来到SO,请使用评论区留下问题。 - Abu Romaïssae
我也遇到了同样的问题,我的DTO上有DataContract和DataMember属性,但我已经尽量简化它们以使其正常工作,但仍然像你上面的一样崩溃。 - ozz
@Ozz最好能为您的问题创建一个单独的问题,包括测试代码。一旦您这样做了,我可以看一下,看看我是否能够确定您问题的原因。 - mickfold
2个回答

6
我发现了我的问题根源。我的某个DTO没有使用[DataContract][DataMember]属性进行修饰。
这意味着ServiceStack生成的WSDL未包含此DTO的类型信息。因此,当WSDL的某个消息子部分引用此DTO类型时,VS找不到它并抛出异常。
希望这能帮助其他人。我花了相当长的时间才弄清楚我的错误所在。

1
是的,这已经在SOAP支持wiki页面中列出了,需要确保DTO对象具有[DataContract]属性... - mythz

0
另一个可能的原因是:检查targetNamespace可能会创建冲突,请删除任何tempuri.org的实例 - 适当放置一致的命名空间,将解决上述错误。
targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IMyInterafaceService' 

希望能有所帮助


只要一直使用,使用 tempuri.org 没有任何本质上的问题。 - Abel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接