locked
Calling RestFul Services RRS feed

  • Question

  • I am trying to call the RestFull Services from Biztalk 2013 R2. I am trying to change the existing one using Http adapter like below

    System.Diagnostics.EventLog.WriteEntry("ABC", Message_Datasheets(FILE.ReceivedFileName));
    varNewSearchDataLoadURL = System.Configuration.ConfigurationManager.AppSettings["NewSearchDataLoadURL"];
    varNewXmlMsg = new System.Xml.XmlDocument(); 
    varNewXmlMsg.LoadXml(@"<path>" + Message_Datasheets(FILE.ReceivedFileName) + @"</path>");
    Message_NewUnZip = varNewXmlMsg;
    Message_NewUnZip(HTTP.RequestTimeout) = 3600;
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" + Message_Datasheets(FILE.ReceivedFileName);
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.TransportType) = "HTTP"

    I tried to change it to WCF-WebHttp adapter to call the Restful services. And the Message Construction looks like below.

    System.Diagnostics.EventLog.WriteEntry("ABC", Message_Datasheets(FILE.ReceivedFileName));
    varNewSearchDataLoadURL = System.Configuration.ConfigurationManager.AppSettings["NewSearchDataLoadURL"];
    varNewXmlMsg = new System.Xml.XmlDocument(); 
    varNewXmlMsg.LoadXml(@"<path>" + Message_Datasheets(FILE.ReceivedFileName) + @"</path>");
    Message_NewUnZip = varNewXmlMsg;
    Message_NewUnZip(WCF.HttpMethodAndUrl) = @"<BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET'/></BtsHttpUrlMapping>";
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" + Message_Datasheets(FILE.ReceivedFileName);
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.TransportType) = "WCF-WebHttp";
    Message_NewUnZip(WCF.SuppressMessageBodyForHttpVerbs) = "GET";
    

    I am not sure if this is the correct way to do it. Because I was following the here and was not sure about the BtsVariablePropertyMapping.

    Please help me with this.Thanks

    Thursday, July 23, 2015 1:48 PM

Answers

  • The below code works, without using the BtsVariablePropertyMapping

    System.Diagnostics.EventLog.WriteEntry("ABC",   Message_Datasheets(FILE.ReceivedFileName));
    varNewSearchDataLoadURL = System.Configuration.ConfigurationManager.AppSettings["NewSearchDataLoadURL"];
    varNewXmlMsg = new System.Xml.XmlDocument(); 
    varNewXmlMsg.LoadXml(@"<path>" +   Message_Datasheets(FILE.ReceivedFileName) + @"</path>");
    Message_NewUnZip = varNewXmlMsg;
    Message_NewUnZip(WCF.HttpMethodAndUrl) = @"<BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET'/></BtsHttpUrlMapping>";
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" +    Message_Datasheets(FILE.ReceivedFileName);
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.TransportType) = "WCF-WebHttp";
    Message_NewUnZip(WCF.SuppressMessageBodyForHttpVerbs) = "GET";
    • Proposed as answer by Koushik984 Tuesday, July 28, 2015 7:42 AM
    • Marked as answer by Angie Xu Thursday, July 30, 2015 1:37 AM
    Monday, July 27, 2015 2:41 PM

All replies

  • Hi Vdha,

    I have been doing the same but have embedded wcf-behaviour, the reason is, by using BtsVariablePropertyMapping within the orchestration, we will have go towards promoted property whcih can be avoided with custom WCF behaviour. Note that my solution is still under construction because it does a POST instead of GET although SuppressVerb is enforced. But I hope this generic block below will help you build the variable mapping out. 

    Here is block of code you can reuse to build 

            public string BuildVariableMappings(XmlDocument transformedMsg, string _httpMethodAndUrl)
            {
                XmlDocument httpMethodAndUrl = new XmlDocument();
                httpMethodAndUrl.LoadXml(_httpMethodAndUrl);
    
                XmlDocument btsVariableMapping = this.BuildVariableMappings(transformedMsg, httpMethodAndUrl);
                return btsVariableMapping.InnerXml.ToString();
            }
    
            public XmlDocument BuildVariableMappings(XmlDocument transformedMsg, XmlDocument httpMethodAndUrl)
            {
                XmlDocument variableMappings = new XmlDocument();
    
                try
                {
                    //Fetch URL from the Opreations Attribute
                    XmlNode operation = httpMethodAndUrl.SelectSingleNode("/BtsHttpUrlMapping/Operation");
                    XmlAttribute url = (XmlAttribute)operation.Attributes.GetNamedItem("Url");
    
    
                    //Add variables to the Dictionary
                    Dictionary<string, string> variables = new Dictionary<string, string>();
    
                    //Search for variables in the URL embedded within {}
                    string[] uriNodes = url.Value.Split('/');
                    foreach (string uriNode in uriNodes)
                    {
                        if (uriNode.Contains("{"))
                        {
                            string tempUriNode = uriNode.Replace("{", "");
                            tempUriNode = tempUriNode.Replace("}", "");
    
                            //Get respective value from the transformedMsg
                            XmlNode valueNode = transformedMsg.SelectSingleNode("//" + tempUriNode);
    
                            variables.Add(tempUriNode, valueNode.InnerText);
                        }
                    }
    
    
                    //Build BtsVariableMapping
    
                    if (variables.Count > 0)
                    {
                        string variableNode = "";
    
                        foreach (string key in variables.Keys)
                        {
                            string val;
                            variables.TryGetValue(key, out val);
    
                            variableNode = variableNode + "<Variable Name=\"" + key + "\" PropertyName=\"" + val + "\" PropertyNamespace=\"https://BP.REST.Schemas\"/>";
                        }
    
                        variableNode = (("<BtsVariablePropertyMapping>" + variableNode + "</BtsVariablePropertyMapping>").Replace('\"', '"'));
    
                        variableMappings.LoadXml(variableNode);
                    }
    
                }
                catch (Exception ex)
                {
                    TraceManager.CustomComponent.TraceError(ex);
                }
    
                return variableMappings;
            }

    Expected out will be: 

    <BtsVariablePropertyMapping><Variable Name=\"childId\" PropertyName=\"1234\" PropertyNamespace=\"https://BP.REST.Schemas\" /></BtsVariablePropertyMapping>

    Hope that helps.


    • Edited by Koushik984 Friday, July 24, 2015 10:19 AM rearranged wording
    Friday, July 24, 2015 10:16 AM
  • Thanks Koushik but I dont have anything in the Schema to be promoted. With respect to my scenario I am not sure what is needed to be promoted.

    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" + Message_Datasheets(FILE.ReceivedFileName);

    Here the varNewSearchDataLoadURL holds "new.abc.org/AbcSearchWebApi/api/search/loaddatafeed in the webconfig file.

    Can you please explain me little with respect to my scenario. May be I am missing something. Any help is greatly appreciated.

    Friday, July 24, 2015 11:53 AM
  • In BtsHttpUrlMapping, update the Operation to include the Url:

    <BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET' Url="/path={pathVariable}"/></BtsHttpUrlMapping>

    Now "pathVariable" value is intended to be the received file name. Here you will need a property schema in the solution. Lets say the name provide is "pathVariable_prop" under namespace "pathVariable_Prop", the following will be the variable mapping. 

    <BtsVariablePropertyMapping><Variable Name=\"pathVariable\" PropertyName=\"pathVariable_prop\" PropertyNamespace=\"https://REST.Schemas\" /></BtsVariablePropertyMapping>

    Friday, July 24, 2015 12:42 PM
  • So do you ask me to create a schema with pathVariable_prop as the field. Here how do I pass the value of the Received File name in to the Schema field.Also URL address going to have three things right

     varNewSearchDataLoadURL + "?path=" + Message_Datasheets(FILE.ReceivedFileName);

    How do I specify in the

    <BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET' Url="/path={pathVariable}"/></BtsHttpUrlMapping>

    I am sorry may be I am missing some basic thing to understand.

    Doesn't this work give directly the URL

    System.Diagnostics.EventLog.WriteEntry("ABC", Message_Datasheets(FILE.ReceivedFileName));
    varNewSearchDataLoadURL = System.Configuration.ConfigurationManager.AppSettings["NewSearchDataLoadURL"];
    varNewXmlMsg = new System.Xml.XmlDocument(); 
    varNewXmlMsg.LoadXml(@"<path>" + Message_Datasheets(FILE.ReceivedFileName) + @"</path>");
    Message_NewUnZip = varNewXmlMsg;
    Message_NewUnZip(WCF.HttpMethodAndUrl) = @"<BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET'/></BtsHttpUrlMapping>";
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" + Message_Datasheets(FILE.ReceivedFileName);
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.TransportType) = "WCF-WebHttp";
    Message_NewUnZip(WCF.SuppressMessageBodyForHttpVerbs) = "GET";

    • Edited by vdha Friday, July 24, 2015 1:01 PM
    Friday, July 24, 2015 12:59 PM
  • The below code works, without using the BtsVariablePropertyMapping

    System.Diagnostics.EventLog.WriteEntry("ABC",   Message_Datasheets(FILE.ReceivedFileName));
    varNewSearchDataLoadURL = System.Configuration.ConfigurationManager.AppSettings["NewSearchDataLoadURL"];
    varNewXmlMsg = new System.Xml.XmlDocument(); 
    varNewXmlMsg.LoadXml(@"<path>" +   Message_Datasheets(FILE.ReceivedFileName) + @"</path>");
    Message_NewUnZip = varNewXmlMsg;
    Message_NewUnZip(WCF.HttpMethodAndUrl) = @"<BtsHttpUrlMapping><Operation Name = 'RESTGet' Method ='GET'/></BtsHttpUrlMapping>";
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.Address) = varNewSearchDataLoadURL + "?path=" +    Message_Datasheets(FILE.ReceivedFileName);
    Port_NewSearch_API(Microsoft.XLANGs.BaseTypes.TransportType) = "WCF-WebHttp";
    Message_NewUnZip(WCF.SuppressMessageBodyForHttpVerbs) = "GET";
    • Proposed as answer by Koushik984 Tuesday, July 28, 2015 7:42 AM
    • Marked as answer by Angie Xu Thursday, July 30, 2015 1:37 AM
    Monday, July 27, 2015 2:41 PM
  • Hi Vdha,

    I replicated the scenario in my environment and yes infact it works without Variable mapping. In the event viewer there is message: 

    The adapter failed to transmit message going to send port "SndPrt_RestServiceOut" with URL "http://localhost:7042" It will be retransmitted after the retry interval specified for this Send Port. Details:"System.ArgumentException: A property with the name 'http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties#VariablePropertyMapping' is not present.

    K

    Tuesday, July 28, 2015 7:42 AM