问题 以编程方式创建WCF客户端


我有一个支持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'.."}

如何正确创建我的客户端,以便这些正确“匹配”?
提前致谢!!!


3521
2017-10-30 16:41


起源

Sivlerlight不支持WSHttpBinding。 msdn.microsoft.com/en-us/library/cc896571(VS.95).aspx - Andrew Shepherd


答案:


啊---找到了。该 ServiceModel 网站上的部分 web.config 被设定为 customBinding。将其更改为与客户端发送的内容相匹配,现在它的工作效果非常好。


11
2017-10-30 16:52



还要确保你的 合同 在服务器端点匹配所以正确 customBindings 使用。 - SliverNinja - MSFT


我遇到了同样的问题。更具说服力的是我的修复是更新我正在使用的绑定类型。我在用 wsHttpBindings 代替 basicHttpBindings。这导致了失败 wsHttpBindings 使用SOAP 1.2 basicHttpBindings 使用SOAP 1.1和我使用的服务所需的SOAP 1.1


3
2017-12-08 18:37





我有同样的错误。服务正在编译,客户端也是如此。客户端应用程序中的服务引用是成功更新引用。我已经尝试删除并再次添加引用,它是无益的。问题出在Web服务中删除的界面。


0
2018-01-06 17:50