WCF-解决使用自定义端点行为时的问题
本文关键字:问题 端点 解决 自定义 WCF- | 更新日期: 2023-09-27 18:19:37
我正在尝试在我的WCF服务中实现一个自定义端点/操作扩展。我已经在websconfig中连接了我的自定义扩展,这样我就可以装饰我的服务&以及具有属性的操作。然而,在这样做之后,我得到了以下错误:
带有"收件人"的邮件http://localhost:1605/Graph.svc/Triples/vbid/abk9185/0/en-由于EndpointDispatcher处的AddressFilter不匹配,无法在接收器处处理"us"。检查发送方和接收方的EndpointAddresses是否一致。
我已经做了很多搜索,但我不知道这个错误意味着什么,也不知道如何修复它。有人能帮忙吗?
这是我将端点和操作行为"注入"到的服务:
<service name="Services.Graph" behaviorConfiguration="Services.DefaultBehavior">
<endpoint address="" binding="webHttpBinding" contract="Services.IGraphService" behaviorConfiguration="corsMessageInspection"
bindingConfiguration="LargeMessageBinding" bindingNamespace="http://icp.myorg.org">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
以下是我的端点和服务行为配置:
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
<behavior name="corsMessageInspection">
<endpointMessageInspector />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Services.DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
这是我的自定义端点/操作扩展配置:
<extensions>
<behaviorExtensions>
<add name="endpointMessageInspector" type="org.myorg.wcf.cors.CorsEndPointExtensionElement, org.myorg.wcf.cors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
最后,这里是我的服务合同的一个例子:
[ServiceContract(Namespace = "http://icp.myorg.org")]
[CorsBehavior]
public interface IGraphService
{
[OperationContract]
[CorsBehavior]
[WebInvoke(Method = "*", UriTemplate = "Triples/{library}/{subjectLocalPart}/{depth}/{languageCode}")]
GraphNode ReadTriple(string library, string subjectLocalPart, string depth, string languageCode);
"CorsBehavior"是我的自定义属性,它实现了IEndPointBehavior和IOperationBehavior。
如果您希望遵守[WebInvoke]
属性,那么您还需要将WebHttpBehavior(<webHttp/>
)添加到端点行为中。更改端点(corsMessageInspection)引用的行为,使其同时具有webHttp行为和自定义行为:
<endpointBehaviors>
<behavior name="corsMessageInspection">
<webHttp />
<endpointMessageInspector />
</behavior>
</endpointBehaviors>