none
WCF WebHttp Header Properties(Wcf.HttpHeaders) setting Dynamically

    Question

  • Hello,

    I have a requirement to set some of the Http Header properties dynamically using wcf webhttp send port communicating with API.

    I have followed some technical forums and I came to know that we need to use either Custom pipeline or WCF behavior extensions to set HttpHeaders.Please correct if my understanding is wrong.

    Based on the link shared below(discussions), I have followed some steps to set these properties. Please let me know if not right..

    1.Created a property schema(Message context property Base)

    2.In orchestration I'm doing the transformation in message assignment shape and setting the HttpHeader properties as

    Msg_Out=Msg_In;

    Msg_Out(Test.PropertySchema.ClientID)=Value;
    Msg_Out(WCF.SecurityMode)="Transport";
    Msg_Out(WCF.TransportClientCredentialType) = "Basic";
    Msg_Out(WCF.UserName)=strUserID;
    Msg_Out(WCF.Password)=strPassword;
    Msg_Out(WCF.HttpMethodAndUrl) = "GET";

    Msg_Out(WCF.OpenTimeout)= "00:10:00";
    Msg_Out(WCF.CloseTimeout)= "00:10:00";
    Msg_Out(WCF.SendTimeout)= "00:10:00";
    Msg_Out(WCF.MaxReceivedMessageSize)= 2147483647;

    Msg_Out(WCF.HttpHeaders)= "ClientID:"+Value;

    Request_Response_SendPort(Microsoft.XLANGs.BaseTypes.Address)="https://sampleURL";
    Request_Response_SendPort(Microsoft.XLANGs.BaseTypes.TransportType)="WCF-WebHttp";

    3. I have created a Custom Send pipeline and I have written the properties to message context.

    When I try to hit the API URL, using the dynamic send port ,the HttpHeader properties are not set(Please note for static port it works fine).

    Can you please help me how and where can we find the HttpHeader properties in Send pipeline.In admin console I can see the context properties are written but not promoted. Should I promote them..I mean HttpHeaders?

    Also can someone tel me what should be the exact things that should go in Execute method? Should I read the Value from Message Context property schema?

    I'm using the below code for Execute Method.

    Should I use any code in IPropertybag? I'm just loading and saving the properties.

    I have tried with all these information but no luck.

    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
    {
        
    
        pInMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", "ClientID: "+Value);
    
        return pInMsg;
    }

    I have also followed this post for more information

    https://social.msdn.microsoft.com/Forums/en-US/6d05e54e-3521-4fa5-9e04-b3cdd4e2c40b/biztalk-wcfwebhttp-custom-headers-per-message?forum=biztalkgeneral

    Thanks

     


    Sri



    • Edited by Sriram27 Thursday, February 23, 2017 4:25 PM
    Thursday, February 23, 2017 4:21 PM

Answers

  • Great.

    The header separator is \r\n but, for some reason, that syntax is a bit flaky in how escaping is handled.

    Try forming the value string before hand with \r\n and using the variable in the Write method.

    • Marked as answer by Sriram27 Friday, February 24, 2017 1:16 PM
    Friday, February 24, 2017 12:39 PM
    Moderator

All replies

  • That is the correct Property.

    Have you tried using Fidder or such to verify the headers yourself?

    Thursday, February 23, 2017 6:39 PM
    Moderator
  • Hi,

    I haven't used Fiddler to trace out.

    I will you posted if I find any.

    Where can I trace out the custom pipeline to see the above ClientID is being written or promoted?

    Thanks


    Sri

    Friday, February 24, 2017 2:07 AM
  • Hi

    Just writing to the context is enough, promotion is not required.


    Thanks Arindam

    Friday, February 24, 2017 5:53 AM
    Moderator
  • Hi Arindam,

    Thanks. I am able to see the httpheader properties written to the message context.But I have a combination of ClientID and secret.

    When I pass only the ClientID it says, ID not registered and when I pass both(ClientID and Secret) it says..invalid ClientID or secret.

    In my Custom pipeline,I'm trying to Write to the message context as

    ClientID:XXXX

    Secret: YYYY

    When I write the data in event log I'm able to see Secret is in next line but somehow the HttpHeaders context is not picking the correct value.

    public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
    { pInMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", "ClientID: "+Value +"\n"+"Secret:"+Value2);

    return pInMsg;

    "\n" is writing in the next line but the Context property doesn't
       

    Can you please assist me on this?

    Thanks


    Sri



    • Edited by Sriram27 Friday, February 24, 2017 11:20 AM
    Friday, February 24, 2017 11:02 AM
  • Great.

    The header separator is \r\n but, for some reason, that syntax is a bit flaky in how escaping is handled.

    Try forming the value string before hand with \r\n and using the variable in the Write method.

    • Marked as answer by Sriram27 Friday, February 24, 2017 1:16 PM
    Friday, February 24, 2017 12:39 PM
    Moderator
  • Hi Johns,

    Awesome! It worked..Thanks for your help:)

    Thank you all for your suggestions and assistance


    Sri

    Friday, February 24, 2017 1:15 PM