我尝试在 WCF 服务中使用二进制消息编码,遵循本网站上的许多示例。
在服务器上,我将绑定(bind)声明为:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
服务设置为使用它(我认为):
<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">
<endpoint
address=""
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService" />
客户端有相同的声明:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="4096000" maxSessionSize="4096000" maxWritePoolSize="4096000">
<readerQuotas maxDepth="32" maxStringContentLength="4096000"
maxArrayLength="4096000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="4096000" maxBufferSize="4096000" maxReceivedMessageSize="4096000"/>
</binding>
</customBinding>
和:
<endpoint
address="http://foo.com/ContentUploadService.svc"
binding="customBinding"
bindingConfiguration="binaryHttpBinding"
contract="MyService.IContentUpload"
name="MyService.ContentUploadService"/>
客户端似乎在工作,但服务器抛出一个异常,表明绑定(bind)未到位:
Content Type application/soap+msbin1 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
紧接在日志文件中的这个错误之前是这个错误,在尝试打开服务主机时抛出,这一定是原因。
Configuration evaluation context not found.
我为这条消息尝试过的所有搜索链接都没有帮助。那么,我缺少什么基本部分?
最佳答案
您是否尝试过在服务器上设置主机来补充端点?
我想应该是这样的:
<service behaviorConfiguration="MyService.ServiceBehavior" name="MyService.ContentUploadService">
<host>
<baseAddresses>
<add baseAddress="http://foo.com/ContentUploadService.svc"/>
</baseAddresses>
</host>
<endpoint address="" binding="customBinding" indingConfiguration="binaryHttpBinding" contract="MyService.IContentUpload" name="MyService.ContentUploadService" />
希望对你有帮助
关于c# - 无法在服务器上激活二进制 http 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6010760/