locked
It is posible to specify SoapAction of a WebMethod?

    Question

  • Hi

    I am creating a software component that, depending on what it is asked to do, connects to different webservices, all these webservices have the
    same webmethod (or signature), let's say 'foo(param1, param2, param3)' and all return a same data type.


    I'm doing that in the software component this way:

    MyService myWS = new MyService();
    myWS.Url = newUrl;
    return myWS.foo(param1, param2, param3);

    To do this, I initially created a web reference to one of those webservices (class MyService) and, as you can see, the idea is just to modify
    the webservice url to point to a different webservice (newUrl would be a parameter)


    Everyone of these webservices has different namespaces, what traduces in different SoapAction elements for every webmethod foo(param1, param2, param3).

    For MyService the SOAPAction is:
    SOAPAction: "urn:ws:MyService/foo"

    For OtherService the SOAPAction is:
    SOAPAction: "urn:ws:OtherService/foo"

    For ThirdService the SOAPAction is:
    SOAPAction: "urn:ws:ThirdService/foo"


    My problem is that I'm getting SoapException "Server did not recognize value of HTTP Header SOAPAction" because everyone of these webservices
    have a different namespace.

    More about the exception:
    System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: The request element <foo xmlns=urn:ws:OtherService'> was not recognized.

    I would like to leave the webservices with different namespaces, but I need the SOAPAction for them to be the same if I want my software component to work.

    So, I need to know if it is posible to specify SoapAction of a WebMethod.

    Thank you for your help.
    Blessings

    Friday, August 07, 2009 1:50 PM

Answers

  • No, you can't set the SOAP Action at runtime.

    Why do the services all have different namespaces if they all have the same operation with the same parameters? If this is three identical instances of the same service, then they should all use the same namespace.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Friday, August 07, 2009 2:54 PM

All replies

  • No, you can't set the SOAP Action at runtime.

    Why do the services all have different namespaces if they all have the same operation with the same parameters? If this is three identical instances of the same service, then they should all use the same namespace.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Friday, August 07, 2009 2:54 PM
  • Ouch...

    Thanks for your response.

    The services have different namespaces because they "represent" different entities, they are not the same service, but they receive the same parameters.

    I have got a possible solution by dynamically invoking Web Service At Runtime (like specied in http://www.crowsprogramming.com/archives/66), do you know if it has a great impact in a system (memory, response time)
    Friday, August 07, 2009 3:07 PM
  • Of course, dynamically invoking the service will have a lot of overhead.

    Why not give all three services the same SOAPaction?

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Friday, August 07, 2009 3:13 PM
  • Basically because the namespace is a URN that should identify uniquely a resource, its a name of a resource and those resources are different.

    (ñ_ñ)
    Our development team will have to evaluate the option of a unique namespace (but I think it losses its meaning) or a dynamic approach.


    Thank you very much for your advice.


    Just one more question, using [SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)] would help?
    I have been investigating but it has problems with ws-secutity because it encrypts the body part.





    Friday, August 07, 2009 8:07 PM
  • The SOAP Action does not need to be in the same namespace.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Monday, August 10, 2009 5:17 PM
  • You can specify the SoapAction of a WebMethod by applying [SoapDocumentMethod] attribute on your webmethod. It accepts "action" as an argument, you can specify the soapaction in this argument and it will change.
    Friday, September 25, 2009 7:21 AM