以编程方式创建WCF客户端

时间:2009-10-30 16:41:33

标签: wcf-client type-mismatch

我的网站上有支持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'.."}

如何正确创建我的客户端以使其正确“匹配”? 在此先感谢!!!

3 个答案:

答案 0 :(得分:11)

啊,发现了。网站web.config中的 ServiceModel 部分设置为 customBinding 。改变它以使其与客户端发送的内容相匹配,现在它可以很好地工作。

答案 1 :(得分:3)

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

答案 2 :(得分:0)

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

相关问题