【问题标题】:Cannot import wsdl:portType, wsdl:binding, wsdl:port errors with WCF in Silverlight Application无法在 Silverlight 应用程序中使用 WCF 导入 wsdl:portType、wsdl:binding、wsdl:port 错误
【发布时间】:2015-08-05 21:40:09
【问题描述】:

我有一个 Silverlight 应用程序,它通过 WCF 服务与服务器端的 ADO.Net 数据实体进行通信。实际上,我使用多个 WCF 服务与三个不同的数据 ADO.Net 数据实体进行通信。我最初在 Visual Studio 2010 上构建了这个项目,最近大约一周前转移到了 Visual Studio Professional 2012(试用版)。最初一切正常/移植良好,直到大约一个小时前我对服务没有任何问题。不到一个小时前,我实际上在我的代码中使用了这些相同的 WCF 服务。但是,当我添加一种将 xml 字符串插入数据库的方法时,我收到了这个错误:

Content Type text/xml; charset=utf-8 was not supported by service . The client and service bindings may be mismatched.

但我检查了绑定,据我从 ServiceReferences.ClientConfig 文件中得知,它们是 basicHttpBinding。我环顾四周寻找解决方案,我能找到的唯一一个建议删除服务引用并在重新启动 Visual Studio 后阅读它,所以我终于尝试了,但现在,即使删除了我添加的方法,我现在收到此错误时我尝试在客户端上添加服务引用:

Warning 6   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Exception has been thrown by the target of an invocation.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IXMonitorXMLDataService']    C:\Users\ckarrs\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1\Service References\XMonitorXMLDataService\Reference.svcmap  1   1   SL_xMonitor_Frontend_RefactorV1


Warning 7   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='IXMonitorXMLDataService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IXMonitorXMLDataService']    C:\Users\ckarrs\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1\Service References\XMonitorXMLDataService\Reference.svcmap  1   1   SL_xMonitor_Frontend_RefactorV1

Warning 8   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://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IXMonitorXMLDataService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='XMonitorXMLDataService']/wsdl:port[@name='BasicHttpBinding_IXMonitorXMLDataService']  C:\Users\ckarrs\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1\Service References\XMonitorXMLDataService\Reference.svcmap  1   1   SL_xMonitor_Frontend_RefactorV1

Warning 9   Custom tool warning: No endpoints compatible with Silverlight 5 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.  C:\Users\ckarrs\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1\Service References\XMonitorXMLDataService\Reference.svcmap  1   1   SL_xMonitor_Frontend_RefactorV1

Warning 10  Custom tool warning: Exception has been thrown by the target of an invocation.  C:\Users\ckarrs\Documents\Visual Studio 11\Projects\SL_xMonitor_Frontend_RefactorV1_Backup82212\SL_xMonitor_Frontend_RefactorV1\Service References\XMonitorXMLDataService\Reference.svcmap  1   1   SL_xMonitor_Frontend_RefactorV1

我很困惑。其他服务引用保持不变,并且该服务完全正常工作,直到我尝试添加并更新引用。这是 VS 2010 和 2012 之间的兼容性问题吗? MSDN 网站称 VS 2012 向后兼容 VS 2010,一切似乎都可以正常迁移。非常感谢任何帮助,我很困惑。如果需要其他信息,请告诉我。

【问题讨论】:

  • 请向我们展示您添加的 OperationContract。我敢打赌它使用 Silverlight 不支持的 .NET 类型。
  • 如果您可以发布一段重现代码将很有帮助。谢谢,普拉布拉杰
  • 我也有兴趣看到这个问题的答案。我看到一个非silverlight应用程序尝试使用来自asp.net asmx服务的服务时出现同样的问题。
  • 嗨,对不起,我一直忙于工作,无法发布,但我今晚会尝试发布请求的 OperationContract 和代码。此外,我没有遇到任何问题,因为在添加服务引用时确保取消选中高级设置下的“在所有引用的程序集中重用类型”框。重用类型似乎有些问题。

标签: c# .net wcf visual-studio-2012 silverlight-5.0


【解决方案1】:

我不是 WCF 专家,但我了解 .net Web 服务和 WSDL,因此如果信息与 WCF 无关,请更正。

错误提示:An exception was thrown while running a WSDL import extension。这意味着,VS 无法正确读取服务 WSDL 文件,也无法创建它需要的代理客户端类,以便进行服务调用。

因为引用 Web 服务的 .net 应用程序会自动获取 WSDL,有时它不是它所期望的,这可能会导致麻烦。有一种方法可以配置 WSDL 文件的生成方式,但不是那么容易做到 (read more here)

尝试通过在浏览器中的服务 URL 后键入 ?wsdl 查询来获取 WSDL 文件,并查看其中的内容。如果服务器位于代理服务器后面,这可能会导致问题。在 WSDL 文件的末尾,您将找到“绑定”、“端点”和“端口”标签/属性。

根据您发布的错误消息,WSDL 不符合预期的架构,解析失败。

一个简单的解决方法是,如果您可以访问服务器,将生成的 WSDL 文件保存在服务所在的同一目录中,根据您的需要修改 WSDL 文件,然后添加对在您的客户端应用程序中修改后的 WSDL 文件。当然,这有一个副作用,即每次更改服务定义时文件都不同步。所以如果你打算在未来改变很多方法,也许更好的是改变/修复自动WSDL generation

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2011-05-29
    • 2011-03-19
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2018-05-03
    相关资源
    最近更新 更多