我有一个 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 不是可识别的元素。
- 如果我将这些行放在自定义绑定标记下方,则会收到一条错误消息,指出 wsHttpBinding 没有定义 CustomMapper!?
有人可以解释如何将自定义类型映射器与 webHttpBinding 一起使用吗?
如果您定义了完整的自定义绑定(就像您在此处所做的那样)CustomMapper
):
<binding name="CustomMapper">
<webMessageEncoding webContentTypeMapperType=
"IndexingService.CustomContentTypeMapper, IndexingService" />
<httpTransport manualAddressing="true" />
</binding>
那么您需要在服务端点中使用该自定义绑定 - 而不是 webHttpBinding!这个配置部分做了not仅定义一个绑定配置!
在这里尝试这个配置:
<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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)