【问题标题】:Cannot activate binary http binding on server无法在服务器上激活二进制 http 绑定
【发布时间】:2011-05-15 19:43:57
【问题描述】:

我正在尝试在 WCF 服务中使用二进制消息编码,遵循此站点上的许多示例。

在服务器上,我将绑定声明为:

<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"/>

客户端似乎在工作,但服务器抛出异常,表明绑定未到位:

内容类型 application/soap+msbin1 被发送到期望的服务 文本/xml;字符集=utf-8。客户端 和服务绑定可能是 不匹配。

日志文件中紧接在此错误之前的是这个,在尝试打开服务主机时抛出,这一定是原因。

配置评估上下文不 找到了。

我为此邮件尝试的搜索链接都没有帮助。那么,我缺少什么基本部分?

【问题讨论】:

  • web.config中有服务配置吗?您的服务器应用程序中是否引用了 System.ServiceModel.dll?
  • 是的,是的。如果我将绑定更改为 basicHttpBinding(只要消息大小保持
  • Configuration evaluation context not found 通常会在您使用一些未注册为扩展的未知绑定或行为配置时被触发。确保您的配置中没有类型。还要确保您的服务/@name 正确 - 它必须是 .svc 文件中定义的 Namespace.ServiceName。
  • 二进制消息编码的任何部分是否在其他地方声明(在 System.ServiceModel 之外?)。由于该服务使用不同的绑定,要么我声明它不正确,要么我没有需要的参考。
  • 所有二进制编码都在 System.ServiceModel 中声明。您遇到的问题是由于服务无法识别服务的配置(如果没有在服务上声明端点​​,您将获得一个默认端点,恰好使用 BasicHttpBinding)。您是否在 IIS 中托管服务? web.config 是否定义在 IIS 应用程序根目录下?

标签: c# .net wcf wcf-binding


【解决方案1】:

您是否尝试在服务器上设置主机来补充端点?

我想应该是这样的:

<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" />

希望对你有帮助

【讨论】:

    【解决方案2】:

    在我看来,您的服务正在使用默认配置,如果找不到显式配置,就会发生这种情况。确保元素的 name 属性与您的服务类的完全限定名称(包括命名空间)完全匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 2022-01-26
      相关资源
      最近更新 更多