我试图在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 > 500 " />
但每当我运行代码时,我都会得到一个例外情况。 cc:// value1&gt; 500&#39;作为无效的限定名称例外。
我该如何解决这个问题?
答案 0 :(得分:1)
这里有多个错误:
Quantity
根本不在您的服务合同中,因此XML中将完全不存在用于过滤目的。http:orders
时,路由器配置中的命名空间启动http://orders
。/Quantity
。答案 1 :(得分:0)
嘿问题在于
filter name="All" filterType="XPath" filterData="cc://value1 > 500 "
应该是
<filter name="All" filterType="XPath" filterData="//cc:value1 > 500 " />
在你的代码中观察cc://。
这将解决你的问题