none
How to add SOAP header in ASMX client? RRS feed

  • Question

  • Hi,

    A client application connects to an old-school ASMX SOAP web service. I know how to add a SOAP header that is defined in the service. But I want to add a header that isn't defined in the service. That is, I want to add a header element from a namespace not handled by the service. 

    The problem is that the client Proxy classes doesn't seem to expose any way to access the SOAP headers directly?

    -- 
    Werner

    Tuesday, November 12, 2013 8:07 PM

All replies

  • Hi Werner,

    I think you can use like this

    Client side, you can pass a header prior invoking the operation:

    MessageHeader messageHeader = MessageHeader.CreateHeader(_headerName, _headersNameSpace, _headerValue);
    OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);
    and extract it in the server side using FindHeaders Method


    srithar

    Wednesday, November 13, 2013 4:41 AM
  • Hi Werner,

    I think you can use like this

    Client side, you can pass a header prior invoking the operation:

    MessageHeader messageHeader = MessageHeader.CreateHeader(_headerName, _headersNameSpace, _headerValue);
    OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);
    and extract it in the server side using FindHeaders Method


    srithar

    Hi srithar,

    But my client does not have an OperationContext (it is null). It's a client connecting to an ASMX service, so the context here is System.Web.Services.Protocols.SoapHttpClientProtocol.

    But thanks - you saved me a similar question when dealing with WCF client :)

    -- 
    Werner

    Wednesday, November 13, 2013 7:12 AM
  • Hi Werner,

    In case of adding soap headers to ASMX Service. Refer this link

    http://stackoverflow.com/questions/8132887/adding-soap-headers-to-asmx-service-requests 


    srithar

    Wednesday, November 13, 2013 9:32 AM
  • Hi,

    If you want to add SOAP header in the client side, please try to refer to the following similar thread:
    #How do I attach a SOAP Header to my C# client:
    http://stackoverflow.com/questions/7554222/how-do-i-attach-a-soap-header-to-my-c-sharp-client .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 14, 2013 2:39 AM
    Moderator
  • Amy, srithar,

    Thanks both but I don't think you get the picture. I want to add a soapheader NOT defined in the web service. The web service does NOT expose any soapheaders in the wsdl. 

    All the links show how to handle soap headers in the web service, but that is not what I'm after. I'm only interested in how the client would insert a soap header not defined in the service.

    Do you understand?

    -- 
    Werner

    Thursday, November 14, 2013 6:57 AM
  • Hi,

    There is a link about how to use SOAP Headers. Please try to focus on the this section:

    To handle SOAP headers not defined by the XML Web service, but required by an XML Web service client.
    http://msdn.microsoft.com/en-us/library/77hkfhh8(v=vs.71).aspx .

    Hope this helps.

    Best regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 3, 2013 8:09 AM
    Moderator
  • Hi,

    There is a link about how to use SOAP Headers. Please try to focus on the this section:

    To handle SOAP headers not defined by the XML Web service, but required by an XML Web service client.
    http://msdn.microsoft.com/en-us/library/77hkfhh8(v=vs.71).aspx .

    Hope this helps.

    Best regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Hi Amy,

    The headline you reference really says it all: "How to handle ..". It is all about how to handle unknown headers. Not how to define or set them in the client.

    Where is the client example or even description? If you read it (all) you'll see that it all focus on the serverside code - not the client. Or at least I'd like a very strong pointer, because, I have read that webpage 10 times and can't figure out how the client would add a header unknown to the service.

    ?

    -- 

    Werner


    Tuesday, December 3, 2013 10:19 AM