webHttpBinding使用webMessageEncoding:如何配置? [英] webHttpBinding using webMessageEncoding: how to configure?

查看:255
本文介绍了webHttpBinding使用webMessageEncoding:如何配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST WCF服务。它使用的是webHttpBinding,其配置如下所示:

I have a REST WCF service. Its using a webHttpBinding and the configuration looks like this:

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

CustomMapper用于应用自定义WebContentTypeMapper,我尝试将其配置为:

The CustomMapper is used to apply a custom WebContentTypeMapper, which I tried to configure like this:

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

但是我不知道在web.config中应该插入以下行:

But I cannot figure out where in my web.config I should insert these lines:


  • 如果我将这些行放在下面,则会出现错误,因为webMessageEncoding不是可识别的元素。

  • 如果我将行放在自定义绑定标签下,我得到一个错误,即wsHttpBinding没有定义CustomMapper!?

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

Can somebody explain how to use a custom type mapper together with webHttpBinding?

推荐答案

如果定义了完整的自定义绑定(如此处使用 CustomMapper ):

If you define a complete custom binding (as you do here with CustomMapper):

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

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

then you need to use that custom binding in your service endpoint - not webHttpBinding! This config section does not define just a bindingConfiguration!

在此处尝试此配置:

<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

这篇关于webHttpBinding使用webMessageEncoding:如何配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆