WCF routing using XPath : invalid qualified name exception

830 Views Asked by At

I am trying to impelemnt content based routing using XPath in wcf.

I have create class library which contains service contract and data contract as following.

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

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

}

I created one service as follows:

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

And I am trying to implement routing based on 'value'

In app.config (inside router project) i hav added following lines for namespace and XPath filter

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

But whenever i run the code i get an exception for ' cc://value1 > 500 ' as invalid qualified name exception.

How can i resolve this ?

2

There are 2 best solutions below

5
On

There are multiple things wrong here:

  1. The class Quantity on which you appear to want to apply the filter does not feature in your service contract at all, so will be entirely absent in the XML for filtering purposes.
  2. The namespace in your router config starts http:orders, when the service contract namespace starts http://orders.
  3. The namespace in your router config contains /Quantity, when the service contract namespace does not.
  4. The filter xpath cc://value1 is not a valid xpath
  5. ---
0
On

Hey The problem is in the line

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

It should be

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

observe cc:// in ur code.

This will solve ur problem