首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webHttpBinding使用webMessageEncoding:如何配置?

webHttpBinding使用webMessageEncoding:如何配置?
EN

Stack Overflow用户
提问于 2009-09-12 13:18:18
回答 1查看 5.7K关注 0票数 4

我有一个休息WCF服务。它使用一个webHttpBinding,配置如下所示:

代码语言:javascript
复制
<service name="IndexingService.RestService" behaviorConfiguration="IndexingService.Service1Behavior">
    <endpoint
      address=""
      binding="webHttpBinding"
      bindingConfiguration="CustomMapper"
      contract="IndexingService.IIndexingService"
      behaviorConfiguration="webby"/>
</service>

CustomMapper用于应用自定义WebContentTypeMapper,我尝试这样配置它:

代码语言:javascript
复制
<binding name="CustomMapper">
        <webMessageEncoding webContentTypeMapperType="IndexingService.CustomContentTypeMapper, IndexingService" />
        <httpTransport manualAddressing="true" />
</binding>

但我不知道在我的web.config中应该在哪里插入以下几行:

  • 如果将这些行放在下面,就会得到一个错误,因为webMessageEncoding不是一个可识别的元素。如果将这些行放在自定义绑定标记下面,则会得到一个错误,即wsHttpBinding没有定义CustomMapper!?

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-12 13:23:13

如果您定义了一个完整的自定义绑定(就像在这里使用CustomMapper一样):

代码语言:javascript
复制
<binding name="CustomMapper">
   <webMessageEncoding webContentTypeMapperType=
             "IndexingService.CustomContentTypeMapper, IndexingService" />
   <httpTransport manualAddressing="true" />
</binding>

然后,您需要在服务端点中使用自定义绑定-而不是webHttpBinding!这个配置部分不只是定义一个bindingConfiguration!

在这里尝试这个配置:

代码语言:javascript
复制
<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>

Marc

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1415097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档