【问题标题】:Create WCF client programmatically以编程方式创建 WCF 客户端
【发布时间】:2010-12-11 16:18:29
【问题描述】:

我有一个支持 Silverlight 的 WCF 服务的网站。该服务运行良好,我可以毫无问题地在浏览器中浏览到 WSDL 页面。

现在,我正在尝试在 DLL 中创建客户端。不过,我需要以编程方式创建整个客户端,因为它是在 DLL 中调用的,无论出于何种原因(通过设计?),它都不会从自己的配置文件中读取 ServiceModel 部分。

这是我的代码:

Dim endp As EndpointAddress = New EndpointAddress("http://www.mydomain.com/licensing/lic.svc")
Dim bind As WSHttpBinding = New WSHttpBinding()
Dim svc = New lnt.licClient(bind, endp)
Dim rsp = svc.CheckIt(key)

但是当我调用 svc.CheckIt 方法时,我得到以下错误:

Content Type application/soap+xml; charset=utf-8 was not supported by service http://www.mydomain.com/licensing/lic.svc. 
The client and service bindings may be mismatched.
{"The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'application/soap+msbin1'.."}

我如何正确地创建我的客户端,以使它们正确“匹配”??
先谢谢了!!!

【问题讨论】:

标签: wcf-client type-mismatch


【解决方案1】:

我遇到了同样的问题。更具体地说,我的修复是更新我正在使用的绑定类型。我使用的是wsHttpBindings 而不是basicHttpBindings。这导致失败,因为wsHttpBindings 使用 SOAP 1.2 而basicHttpBindings 使用 SOAP 1.1,而我使用的服务需要 SOAP 1.1

【讨论】:

    【解决方案2】:

    我有同样的错误。服务正在编译,客户端应用程序也在编译。客户端应用程序中的服务引用已成功更新引用。我已经尝试再次删除和添加参考,但没有帮助。问题出在 Web 服务中已删除的接口中。

    【讨论】:

      【解决方案3】:

      啊——找到了。网站web.config 中的ServiceModel 部分设置为customBinding。对其进行了更改,使其与客户端发送的内容相匹配,现在效果很好。

      【讨论】:

      • 还要确保您的 Contract 在服务器端点上匹配,以便使用正确的customBindings
      猜你喜欢
      • 2017-03-30
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 2018-09-08
      • 2011-11-07
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多