wcf - 使用 webMessageEncoding 的 webHttpBinding : how to configure?

标签 wcf .net-3.5 rest

我有一个 REST WCF 服务。它使用 webHttpBinding 并且配置如下所示:

<service name="IndexingService.RestService" behaviorConfiguration="IndexingService.Service1Behavior">
    <endpoint
      address=""
      binding="webHttpBinding"
      bindingConfiguration="CustomMapper"
      contract="IndexingService.IIndexingService"
      behaviorConfiguration="webby"/>
</service>

CustomMapper 用于应用自定义 WebContentTypeMapper,我尝试如下配置:

<binding name="CustomMapper">
        <webMessageEncoding webContentTypeMapperType="IndexingService.CustomContentTypeMapper, IndexingService" />
        <httpTransport manualAddressing="true" />
</binding>

但我不知道应该在 web.config 中的哪个位置插入这些行:

  • 如果我将这些行放在下面,则会收到错误,因为 webMessageEncoding 不是可识别的元素。
  • 如果我将这些行放在自定义绑定(bind)标记下方,则会收到一条错误消息,指出 wsHttpBinding 没有定义 CustomMapper!?

有人可以解释如何将自定义类型映射器与 webHttpBinding 一起使用吗?

最佳答案

如果您定义了完整的自定义绑定(bind)(就像您在此处使用 CustomMapper 所做的那样):

<binding name="CustomMapper">
   <webMessageEncoding webContentTypeMapperType=
             "IndexingService.CustomContentTypeMapper, IndexingService" />
   <httpTransport manualAddressing="true" />
</binding>

那么您需要在服务端点中使用该自定义绑定(bind) - 而不是 webHttpBinding!此配置部分仅定义绑定(bind)配置!

在这里尝试这个配置:

<system.serviceModel>
  <bindings>
    <customBinding>
       <binding name="CustomMapper">
          <webMessageEncoding webContentTypeMapperType=
                 "IndexingService.CustomContentTypeMapper, IndexingService" />
          <httpTransport manualAddressing="true" />
       </binding>
    </customBinding>
  </bindings>
  <services>
    <service name="IndexingService.RestService"   
             behaviorConfiguration="IndexingService.Service1Behavior">
        <endpoint
           address=""
            binding="customBinding"
            bindingConfiguration="CustomMapper"
            contract="IndexingService.IIndexingService"
            behaviorConfiguration="webby"/>
     </service>
  </services>
</system.serviceModel>

马克

关于wcf - 使用 webMessageEncoding 的 webHttpBinding : how to configure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1415097/

相关文章:

django - 如何使用 django-rest-framework 和 angularJS 注册用户?

c# - WCF 没有正确超时?

.net - 为什么 WCF 服务要创建自己的类型?

c# - 如何将 PropertyChangedCallback 添加到基类的依赖属性?

rest - 使用 MarkLogic REST API 将文件系统设置为模块数据库

rest - 使用 OpenRasta 将图像作为流或字节数组获取

c# - 无法生成服务引用代码

c# - 放置WCF命名空间与不放置WCF命名空间的区别?

用于缓存接受通用参数的操作的 C# 模式

c# - 在显示其他表单时禁用完整表单