使用XPath进行WCF路由:无效的限定名称异常

时间:2013-05-13 12:44:18

标签: wcf xpath wcf-routing

我试图在wcf中使用XPath阻止基于内容的路由。

我创建了包含服务合同和数据合同的类库,如下所示。

[ServiceContract(Namespace = "http://orders/")]
public interface IService5
{
    [OperationContract]
    string GetData(int value);
}

[DataContract]
public class Quantity
{
    [DataMember]
    public int value1 { get; set; }

}

我按如下方式创建了一项服务:

public class Service5 : IService5
{
    public string GetData(int value)
    {
        return string.Format("You entered in service 5: {0}", value);
    }
}

我正在尝试根据'值'来实现路由。

在app.config(在路由器项目中)我为命名空间和XPath过滤器添加了以下行

<namespaceTable>
  <add prefix="cc" namespace="http:orders/Quantity/"/>
</namespaceTable>
<filters>
  <filter name="All" filterType="XPath" filterData="cc://value1 &gt; 500 " />

但每当我运行代码时,我都会得到一个例外情况。 cc:// value1&gt; 500&#39;作为无效的限定名称例外。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

这里有多个错误:

  1. 您似乎想要应用过滤器的类Quantity根本不在您的服务合同中,因此XML中将完全不存在用于过滤目的。
  2. 当服务合同命名空间启动http:orders时,路由器配置中的命名空间启动http://orders
  3. 当服务合同名称空间不包含时,路由器配置中的名称空间包含/Quantity
  4. 过滤器xpath cc:// value1 不是有效的xpath
  5. ---

答案 1 :(得分:0)

嘿问题在于

filter name="All" filterType="XPath" filterData="cc://value1 &gt; 500 "

应该是

<filter name="All" filterType="XPath" filterData="//cc:value1 &gt; 500 " />

在你的代码中观察cc://。

这将解决你的问题