问题描述
限时送ChatGPT账号..我已经创建了一个可用的 WCF 服务.我现在想为其添加一些安全性以过滤 IP 地址.我已经按照微软在示例中发布的示例尝试添加一个 IDispatchMessageInspector,它将引发调用 AfterReceiveRequest,然后在 IP 地址不在允许列表中时抛出错误.
I have created a working WCF service. I now want to add some security to it to filter Ip Addresses. I have followed the example that microsoft publish in the samples to try and add a IDispatchMessageInspector that will raise a call AfterReceiveRequest and then throw an error if the ip address is not from the allowed list.
看了代码之后;他们已经使用wsHttpBinding"对其进行了配置,但是我想使用webHttpBinding"或basicHttpBinding".但是当我设置它时,我收到错误:
After looking at the code; they have configured it using 'wsHttpBinding', however I want to use 'webHttpBinding' or 'basicHttpBinding'. But when I set it up I get the error:
'http://upload/api/Api.svc/soap' 的端点没有与 None MessageVersion 绑定.'System.ServiceModel.Description.WebHttpBehavior' 仅用于与 WebHttpBinding 或类似绑定一起使用.
The endpoint at 'http://upload/api/Api.svc/soap' does not have a Binding with the None MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings.
我的配置是:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<!--Set up the service-->
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="HmlApi">
<endpoint address="rest" binding="webHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" />
<endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" />
</service>
</services>
<!--Define the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<!---Endpoint -->
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<ipFilter/>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="ipFilter" type="VLSCore2.Api.IpFilterBehaviourExtensionElement, VLSCore2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
所以我想知道如何在不使用 WebHttpBinding 的情况下设置我的消息检查器.这甚至可能吗?
So what im wondering is how I can set up my message inspector without using WebHttpBinding. Is this even possible?
我想使用 SOAP 'basicHttpBinding' 而不是 wsHttpBinding(以及所有 WS*)相关的开销....
I want to use SOAP 'basicHttpBinding' not wsHttpBinding (and all of the WS*) associated overheads....
推荐答案
这只是因为您为 SOAP 和 REST 端点配置了单个端点行为,但 SOAP 端点不能具有 webHttp 行为.您需要将它们分开,以便它们:
This is simply happening because you have configured a single endpointBehavior for both the SOAP and REST endpoints but the SOAP endpoint can't have the webHttp behavior. You need to split these apart so that they are:
<endpointBehaviors>
<behavior name="SOAPDemoEndpointBehavior">
<ipFilter/>
</behavior>
<behavior name="RESTDemoEndpointBehavior">
<ipFilter/>
<webHttp />
</behavior>
</endpointBehaviors>
然后你的端点应该是:
<endpoint address="rest" binding="webHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="RESTDemoEndpointBehavior" />
<endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" behaviorConfiguration="SOAPDemoEndpointBehavior" />
这篇关于为什么我的 WCF 服务给出消息“没有与 None MessageVersion 的绑定"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论