c# - 无法在服务器上激活二进制 http 绑定(bind)

标签 c# .net wcf wcf-binding

我尝试在 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/

相关文章:

c# - 为什么 .NET 异常没有被 try/catch block 捕获?

c# - 如何在不进行轮询的情况下通知我的 C# Windows 应用程序网络状态更改?

c# - 线程池为什么要这样管理线程呢?

c# - 在 task.Factory.FromAsync 中包装 WCF 异步调用不返回任何结果

windows - 如何说服客户升级到 WCF 或为 Remoting 和 WCF 保留两个代码库

c# - 如何将unity 3d场景导出到Android Studio

c# - MVC 4 : Create new Razor View from string not from file path

c# - 将多个 SqlParameter 传递给方法

android - WCF With Android- 绑定(bind)结果与标签或 ListView

c# - LINQ 查询语法是否可以实现基于工厂的对象构造和属性分配?