I'm working on converting an older ASMX Web Service to a WCF Service (I'm not sure if those are even the right terms, the old code has an ASMX file created using the wsdl tool and I'm trying to create the same service using the svcutil tool). Based on the code and experimenting it looks like the old code is routing messages based on the content of that message.
The previous code (simplified) is as follows:
[SoapDocumentService(SoapBindingUse.Literal, SoapParameterStyle.Wrapped, RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class Server : WebService, IServer
{
public Action1Response Action1(Action1Request request)
{
//Do stuff here
}
public Action2Response Action2(Action2Request request)
{
//Do stuff here
}
}
New code for reference:
[ServiceContract]
public class Server : WebService, IServer
{
[OperationContract]
public Action1Response Action1(Action1Request request)
{
//Do stuff here
}
[OperationContract]
public Action2Response Action2(Action2Request request)
{
//Do stuff here
}
}
However, I can't figure out how to something similar in WCF. I tried the SoapDocumentService
but that didn't work. The only other thing I could think of was to do some routing/filtering but I have no idea how I'd make that work. My guess would be to do something like:
<routing>
<namespaceTable>
<add namespace="http://example.org" prefix="ns"/>
</namespaceTable>
<filters>
<filter name="action1" filterType="XPath" filterData="boolean(//ns:Action1Request)"/>
<filter name="action1" filterType="XPath" filterData="boolean(//ns:Action2Request)"/>
</filters>
<filterTables>
<filterTable name="routingTable">
<add filterName="action1" endpointName="Action1Service" />
<add filterName="action2" endpointName="Action2Service" />
</filterTable>
</filterTables>
</routing>
<client>
<!-- Pretty sure this wouldn't work -->
<endpoint name="Action1Service" address="/Server.svc/Action1" binding="basicHttpBinding" contract="*" />
<endpoint name="Action1Service" address="/Server.svc/Action2" binding="basicHttpBinding" contract="*" />
</client>
My question is, how can I make a WCF service to route to different operations based on the content of the message. I have no control over the client, it will only send messages to /Server.svc
. I apologize if I'm using the incorrect terminology here, I'm very new to WCF.