none
how to set HTTP header SoapAction to one value and <wsa:Action> to another value

    Question

  • I need a way, using WCF, to set the HTTP SoapAction header value (to something like "http://www.somewhere.com/WebServiceProcess" ) and also set the <wsa:Action> (WS-ADDRESSING) element in the <soap:Header> to something DIFFERENT ( like "http://www.somewhere.com/WebServiceProcess/ServiceMethod" ). If I use a "basicHttpBinding" the soap acton shows up in the HTTP header and if I use a "wsHttpBinding" the action goes into the <wsa:Action> inside the <soap:Header>. I tried using a custom binding (Soap11Addressing10), but that still only put the action into <wsa:Action>.

    I know this is against W3C protocol which says the 2 header actions, if both non-empty, should match but I need to do this because the web service I'm trying to call (I think it is Java based) requires it. What is the simplest/best way to accomplish this using WCF?
    Friday, February 26, 2010 11:43 PM

Answers

  • I'd still like to use WCF, even if I have to insert my own filter/handler in the chain somehow and modify the <wsa:Action> value. I solved this same problem using WSE 2.0 by creating my own class derived from SoapOutputFilter and inserting it into the WSE output "pipeline". Inside that class, I modified the <wsa:Action> value. What is the corresponding methodology in WCF to accomplish this?

    Also, WSE had already put the action string into BOTH the HTTP header and the <wsa:Action> inside the <soap:Header>.

    Is there a way I can get WCF to do the same thing? All I've seen so far is that WCF puts the action into one or the other but not both places.
    • Proposed as answer by Mog Liang Friday, March 05, 2010 8:00 AM
    • Marked as answer by Mog Liang Monday, March 08, 2010 1:17 AM
    Friday, March 05, 2010 12:54 AM
  • Hi markh_dis,

    My idea is to modify the SOAP header at Message encoding process.

    Please refer to this Sample
    http://msdn.microsoft.com/en-us/library/ms751458.aspx
    This is a custom message encoder sample, the method
                public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
    Could be our intercept point, we could change the SOAP Action header in this method with code below
               message.Headers.Action = "myaction";

    Thanks,
    Mog Liang
    • Proposed as answer by Mog Liang Friday, March 05, 2010 8:00 AM
    • Marked as answer by Mog Liang Monday, March 08, 2010 1:17 AM
    Friday, March 05, 2010 2:23 AM

All replies

  • Hi,

    As I understand, you want the request message from WCF client has address info both on Http header and Soap header with different value.
    Then you need creating custom Message encoder to customize the message format. However, the workload of this approach would be very high.
    The simple way I think, is using stringBuilder to append the request message, then use WebHttpRequest to send the message.

    Thanks,

    Mog Liang
    Monday, March 01, 2010 8:52 AM
  • I'd still like to use WCF, even if I have to insert my own filter/handler in the chain somehow and modify the <wsa:Action> value. I solved this same problem using WSE 2.0 by creating my own class derived from SoapOutputFilter and inserting it into the WSE output "pipeline". Inside that class, I modified the <wsa:Action> value. What is the corresponding methodology in WCF to accomplish this?

    Also, WSE had already put the action string into BOTH the HTTP header and the <wsa:Action> inside the <soap:Header>.

    Is there a way I can get WCF to do the same thing? All I've seen so far is that WCF puts the action into one or the other but not both places.
    • Proposed as answer by Mog Liang Friday, March 05, 2010 8:00 AM
    • Marked as answer by Mog Liang Monday, March 08, 2010 1:17 AM
    Friday, March 05, 2010 12:54 AM
  • Hi markh_dis,

    My idea is to modify the SOAP header at Message encoding process.

    Please refer to this Sample
    http://msdn.microsoft.com/en-us/library/ms751458.aspx
    This is a custom message encoder sample, the method
                public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
    Could be our intercept point, we could change the SOAP Action header in this method with code below
               message.Headers.Action = "myaction";

    Thanks,
    Mog Liang
    • Proposed as answer by Mog Liang Friday, March 05, 2010 8:00 AM
    • Marked as answer by Mog Liang Monday, March 08, 2010 1:17 AM
    Friday, March 05, 2010 2:23 AM