我有一个 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/