Search code examples
c#wcfoperationcontract

Overloading actions wcfservice


Maybe i am mixing up some things but i can not find any questions or documentation on overloading actions for a wcf service recieving SOAP messages.

The goal: I have 3 SOAP messages coming in to my wcf service with the same actionname on the same endpoint. This is fixed and i can not change this.

I would excpect the following wcf interface would work:

    [OperationContract(Action = "urn:oasis:names:tc:SPML:2:0:req/active", Name = "addRequest")]
    void Add(data data);

    [OperationContract(Action = "urn:oasis:names:tc:SPML:2:0:req/active", Name = "modifyRequest")]
    void Modify(psoID psoID, modification modification);

    [OperationContract(Action = "urn:oasis:names:tc:SPML:2:0:req/active", Name = "deleteRequest")]
    void Delete(psoID psoID);

The problem: If i only have one operationalcontract like this my service works but if i have multiple operationalcontracts the following error will popup: `

500System.ServiceModel.ServiceActivationException

I believe it can not have multiple operational contracts with the same actionname. I also believe this should be possible because i am replacing a soap service that does handle all 3 messages with the same actionname. (wcf and soap shouldn't be that far appart?)

I added the operational names in order to fix the problem but without luck.

Any help would be appriciated. Thanks!


Solution

  • The Action property indicates the address the client request, which will be sent to the server and determines the method to be called on the server-side. Here is a client request captured by the Fiddler.

    POST http://10.157.13.69:21011/ HTTP/1.1
    Content-Type: text/xml;charset=utf-8
    SOAPAction: "urn:oasis:names:tc:SPML:2:0:req/active"
    Host: 10.157.13.69:21011
    Content-Length: 162
    Expect: 100-continue
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive

    The SOAPAction HTTP header is the Action name of the operation. The Name property determined the name of the practical method on the client-side.

    ServiceReference1.ServiceClient client = new ServiceClient();
                    client.addRequest(23);
    

    Thereby, unless we change the WCF web service from SOAP web service to Rest API, otherwise, this feature cannot be achieved because the SOAP web service addressing style depends on the Action field.
    Namely, we need to change the service to Restful API by using Webhttpbinding.

    [OperationContract(Action = "urn:oasis:names:tc:SPML:2:0:req/active", Name = "addRequest")]
    [WebGet]
    void Add(int data);
    

    Feel free to let me know if there is anything I can help with.