【问题标题】:WCF - Addressing issue when using custom endpoint behaviorWCF - 使用自定义端点行为时解决问题
【发布时间】:2012-01-06 04:35:00
【问题描述】:

我正在尝试在我的 WCF 服务中实现自定义端点/操作扩展。我已经在 websconfig 中连接了我的自定义扩展,以便我可以使用属性来装饰我的服务和操作。但是这样做之后我收到以下错误:

由于 EndpointDispatcher 的 AddressFilter 不匹配,接收方无法处理带有 To 'http://localhost:1605/Graph.svc/Triples/vbid/abk9185/0/en-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。

【问题讨论】:

    标签: c# wcf web-services rest wcf-behaviour


    【解决方案1】:

    如果您希望 [WebInvoke] 属性得到尊重,那么您还需要将 WebHttpBehavior (&lt;webHttp/&gt;) 添加到您的端点行为中。将端点 (corsMessageInspection) 引用的行为更改为同时具有 webHttp 行为和您的自定义行为:

    <endpointBehaviors>
      <behavior name="corsMessageInspection">
        <webHttp />
        <endpointMessageInspector />
      </behavior>
    </endpointBehaviors>
    

    【讨论】:

    • 那个错误信息让我在一个非常不同的地方寻找。包括你的博客:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多