none
How to create the Request Response Schemas from REST Api Having content type Content-Type: application/x-www-form-urlencoded RRS feed

  • Question

  • Can someone suggest me, how to create the Request Response Schemas from REST Api Having content type Content-Type: application/x-www-form-urlencoded?<o:p></o:p>

    And also in my case I have 2 different api calls; first is the Call to Authenticate service, this service take user name and password and return a token. This token I have to use in subsequent call, my second questions is where can I keep the User Name and Password for Authenticate service?<o:p></o:p>

     

    Thanks<o:p></o:p>

    Yasin<o:p></o:p>

     


    Tuesday, October 11, 2016 2:32 PM

Answers

  • Hi,

    Usually REST API style is associated with JSON formatted payload, although there are no governing bodies like the the W3.org for SOAP or HTTP , with formal specifications.

    In your case looks like the vendor just wants to post data just like you would post from an HTML form and the url is probably REST styled .

    See example.

    FORM-ENCODED / MULTIPART_FORM_DATA : http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1

    The following example illustrates "multipart/form-data" encoding. Suppose we have the following form:
    
     <FORM action="http://server.com/cgi/handle"
           enctype="multipart/form-data"
           method="post">
       <P>
       What is your name? <INPUT type="text" name="submit-name"><BR>
       What files are you sending? <INPUT type="file" name="files"><BR>
       <INPUT type="submit" value="Send"> <INPUT type="reset">
     </FORM>
    
    
    If the user enters "Larry" in the text input, and selects the text file "file1.txt", the user agent might send back the following data:
       Content-Type: multipart/form-data; boundary=AaB03x
    
       --AaB03x
       Content-Dis-data; name="submit-name"
    
       Larry
       --AaB03x
       Content-Dis-data; name="files"; filename="file1.txt"
       Content-Type: text/plain
    
       ... contents of file1.txt ...
       --AaB03x--
    
    
    If the user selected a second (image) file "file2.gif", the user agent might construct the parts as follows:
       Content-Type: multipart/form-data; boundary=AaB03x
    
       --AaB03x
       Content-Dis-data; name="submit-name"
    
       Larry
       --AaB03x
       Content-Dis-data; name="files"
       Content-Type: multipart/mixed; boundary=BbC04y
    
       --BbC04y
       Content-Dis; filename="file1.txt"
       Content-Type: text/plain
    
       ... contents of file1.txt ...
       --BbC04y
       Content-Dis; filename="file2.gif"
       Content-Type: image/gif
       Content-Transfer-Encoding: binary
    
       ...contents of file2.gif...
       --BbC04y--
       --AaB03x--


    Anyway to answer your question, I do not think WCF or Biztalk has a built in message formatter that can do "Form-data" for you .  Your best bet is to have the vendor provide you with the sample http requests and responses and you may to code the message format as shown in http://www.quicklearn.com/blog/2013/08/30/biztalk-server-2013-support-for-restful-services-part-35/

    & https://social.msdn.microsoft.com/Forums/en-US/44b50c97-4be8-40bf-b7c4-e3abf6866637/biztalk-post-formdata?forum=biztalkgeneral

    Although posting form data is not ideal for B2B solutions, some vendors provide this solution mainly due to project constraints that prevents them from changing existing systems and reusing business logic regardless of the interface data format.




    • Edited by lanax Wednesday, October 12, 2016 3:21 AM
    • Marked as answer by GoforWin Monday, October 17, 2016 4:39 PM
    Wednesday, October 12, 2016 12:52 AM
  • Hi,

    Check this out

    BizTalk Mapper Patterns: How to Map Hierarchical Schema to a Name Value Pair

    https://code.msdn.microsoft.com/windowsdesktop/BizTalk-Mapper-Patterns-4041242c

    -----------------------------------------------------------------------------------------------

    • Marked as answer by GoforWin Monday, October 17, 2016 4:39 PM
    Friday, October 14, 2016 1:01 AM

All replies

  • Hi Yaseen,

    You have to get the structures from the api provider..what is the message structure they are using for communication(json,xml ?)

    ..just when sending the request to the api you need to set the proper content type.

    AS for your second question,

    Are username and password coming in the request????

    Or else if they are static use SSO to store the values

    Regards,


    Mandar Dharmadhikari

    Tuesday, October 11, 2016 2:39 PM
  • So, don't focus too much on the Content-Type, in practice, it really never makes a difference.

    What matters is what you will actually be getting.  Xml, JSON, GET?

    If you tell us which of those it will be, we can give you the best advice.

    As for the token, what is you expected call rate for this service?  1/hour, 1000/day.

    If it's a relatively slow moving service, 1000 per day is still slow moving, I always use an Orchestration to deal with the Token. Meaning, the Orchestration does both call the auth service, then applies the token to the actual call. It's very, very rate to have a case where the extra work required to cache the token is worth it.

    Tuesday, October 11, 2016 2:57 PM
  • I will get the xml.

    as I said my main service will post a request with a string message and the token that I have to get by calling the authenticate service , I will not get the User Name and Password in request I have to keep them in BizTalk somewhere like the config file in simple .net project.

     

    To get the token I have to post the user name and password. For further information I am using the Orchestration.

    Thanks

    Yasin

    Tuesday, October 11, 2016 3:38 PM
  • Hi Yasin,

    Get the schema structures from the api vendor then.

    Content type is not going to play any part in the structure of the message you just pass it in the message header while doing the api call.

    Also use the SSO instead of the btsntsvc.exe.config.

    To store and retrive Value from SSO refer,

    Storing BizTalk Orchestration Config and Parameters in SSO


    Mandar Dharmadhikari

    Tuesday, October 11, 2016 3:49 PM
  • I will get the xml.

    as I said my main service will post a request with a string message and the token that I have to get by calling the authenticate service , I will not get the User Name and Password in request I have to keep them in BizTalk somewhere like the config file in simple .net project.

     

    To get the token I have to post the user name and password.

    Then the Content-Type is pretty much irrelevant, so I wouldn't worry about that.  Also, the WCF-WebHttp Adapter is pretty ambivalent about content-type.

    No, I know exactly how these token schemes work.  Can you tell us exactly what credential type is used for the token service?  It should be, or is most often, simple usename/password so you would store them in the Adapter config, which stores them in SSO automatically.

    Still, you can do both from the Orchestration, meaning call the token service, then apply the token to the business call.  No need to cache the token and hopefully, you configure the username and password on the Send Port.

    Let me ask, is Certificate Authentication an option?

    Tuesday, October 11, 2016 4:14 PM
  • How can I configure the user name and password on send port? no certification Authentication is required.


    Tuesday, October 11, 2016 4:26 PM
  • HI Yasin,

    Just refer the transport details in the link shared below. You can set the user name and password there..as Johns suggested it will be automatically stored in the SSO...but are you sure that those user name and password will always remain same???

    https://msdn.microsoft.com/en-us/library/jj572853.aspx


    Mandar Dharmadhikari

    Tuesday, October 11, 2016 4:37 PM
  • Well they can be changed, that is why I want them to be configurable. For my first questions is there any way that I can generate the schema by myself from api URL?

    Tuesday, October 11, 2016 4:48 PM
  • Well No Rest Api doesnot expose the service metadata as such so it is better you request the vendor to share the request response

    Also..if user Id changes then You can change it on the send port or other option for you to do is to add the key value pair in the SSO as per the link I shared.

    Regards,


    Mandar Dharmadhikari

    Tuesday, October 11, 2016 4:54 PM
  • Sure, the credentials can change, but that really doesn't matter, you still store then on the Send Port.

    On the Security Tab, client credential type Basic is username and password.  You then configure then in the User name credentials section.

    If the service is Xml, the owner should provide you with a Schema.  If not, you will need a full sample you can use to generate the Schema in Visual Studio.

    Tuesday, October 11, 2016 5:18 PM
  • my vendor share with me this detail that request is: FORM-ENCODED / MULTIPART_FORM_DATA

    Response is: TEXT/PLAIN.

    What does this mean?

    Tuesday, October 11, 2016 5:46 PM
  • ASk the vendors..what request and response message xsds they expect..ask them for the request adn response schemas

    Regards,


    Mandar Dharmadhikari

    Tuesday, October 11, 2016 5:55 PM
  • Ayayay!  This:

    • request is: FORM-ENCODED / MULTIPART_FORM_DATA
    • Response is: TEXT/PLAIN.

    means absolutely nothing. It the same as saying "the message will use letters and numbers".

    They have to provide you with either a Schema or sample or transaction guide.

    If they can't do that, then your only choice is to set it up, try and see what happens.  Then be ready for anything.


    Tuesday, October 11, 2016 6:05 PM
  • I like the way you said it Johns305 (Y)...sorry if the comment is not valid in the context

    Mandar Dharmadhikari

    Tuesday, October 11, 2016 6:10 PM
  • Hi,

    Usually REST API style is associated with JSON formatted payload, although there are no governing bodies like the the W3.org for SOAP or HTTP , with formal specifications.

    In your case looks like the vendor just wants to post data just like you would post from an HTML form and the url is probably REST styled .

    See example.

    FORM-ENCODED / MULTIPART_FORM_DATA : http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1

    The following example illustrates "multipart/form-data" encoding. Suppose we have the following form:
    
     <FORM action="http://server.com/cgi/handle"
           enctype="multipart/form-data"
           method="post">
       <P>
       What is your name? <INPUT type="text" name="submit-name"><BR>
       What files are you sending? <INPUT type="file" name="files"><BR>
       <INPUT type="submit" value="Send"> <INPUT type="reset">
     </FORM>
    
    
    If the user enters "Larry" in the text input, and selects the text file "file1.txt", the user agent might send back the following data:
       Content-Type: multipart/form-data; boundary=AaB03x
    
       --AaB03x
       Content-Dis-data; name="submit-name"
    
       Larry
       --AaB03x
       Content-Dis-data; name="files"; filename="file1.txt"
       Content-Type: text/plain
    
       ... contents of file1.txt ...
       --AaB03x--
    
    
    If the user selected a second (image) file "file2.gif", the user agent might construct the parts as follows:
       Content-Type: multipart/form-data; boundary=AaB03x
    
       --AaB03x
       Content-Dis-data; name="submit-name"
    
       Larry
       --AaB03x
       Content-Dis-data; name="files"
       Content-Type: multipart/mixed; boundary=BbC04y
    
       --BbC04y
       Content-Dis; filename="file1.txt"
       Content-Type: text/plain
    
       ... contents of file1.txt ...
       --BbC04y
       Content-Dis; filename="file2.gif"
       Content-Type: image/gif
       Content-Transfer-Encoding: binary
    
       ...contents of file2.gif...
       --BbC04y--
       --AaB03x--


    Anyway to answer your question, I do not think WCF or Biztalk has a built in message formatter that can do "Form-data" for you .  Your best bet is to have the vendor provide you with the sample http requests and responses and you may to code the message format as shown in http://www.quicklearn.com/blog/2013/08/30/biztalk-server-2013-support-for-restful-services-part-35/

    & https://social.msdn.microsoft.com/Forums/en-US/44b50c97-4be8-40bf-b7c4-e3abf6866637/biztalk-post-formdata?forum=biztalkgeneral

    Although posting form data is not ideal for B2B solutions, some vendors provide this solution mainly due to project constraints that prevents them from changing existing systems and reusing business logic regardless of the interface data format.




    • Edited by lanax Wednesday, October 12, 2016 3:21 AM
    • Marked as answer by GoforWin Monday, October 17, 2016 4:39 PM
    Wednesday, October 12, 2016 12:52 AM
  • in the data base is where it will get stored but then the data base takes the password and puts SALT on it to some what encrypt them you can do these in PHP calling to a database hidden on your web server

    make sure you encrypt your docs after you get them to work

    you will have to have an authentication server software app the free PHP maker has some

    you may be able to make shift something from one of the free apps in PHP  

    Wednesday, October 12, 2016 12:59 AM
  • lanax<o:p></o:p>

    The request that I have to post is look like as Id=1112212&au=testmessgae&msg=testingmessgae,<o:p></o:p>

    and Yes I have to post the data as Form Post the Link that you provided Is useful and this is what exactly my solution, but Issue is that in this article he has just one Node i.e. Amount on Source Schema, but here in my case I have 3 nodes on Source Schema, my question is that how I can Create the map that I can get the same result as given in proved Article. For Key value set. I.e. my Map output should be like that :<FormValue> <Id>Id</Id><Value>1112212</Value><Id>au</Id><Value>testmessgae</Value<Id>msg</Id><Value>testingmessgae</Value></FormValue><o:p></o:p>

    Thursday, October 13, 2016 3:52 PM
  • Here's the thing.  It really doesn't matter what the Content Type is.  The owner of the service has to tell you what to expect.  They can't just post anything.  No API works that way.

    The Form date isn't the problem so long as you know what to expect and how to treat it.

    Friday, October 14, 2016 12:24 AM
  • Hi,

    Check this out

    BizTalk Mapper Patterns: How to Map Hierarchical Schema to a Name Value Pair

    https://code.msdn.microsoft.com/windowsdesktop/BizTalk-Mapper-Patterns-4041242c

    -----------------------------------------------------------------------------------------------

    • Marked as answer by GoforWin Monday, October 17, 2016 4:39 PM
    Friday, October 14, 2016 1:01 AM
  • Lanax, thanks for this  wonderful article , this is great and has solved half of my problem, now I am able to Post the request, now the response that I get from service this is just a plain text i.e. one line string this would be either Success OR failure, how I can get this response in my orchestration?


    Friday, October 14, 2016 12:53 PM
  • Johns-305, I don’t know how true this stamen is that Content Type does not matter, but here in my case this does and I have completed the flow and this is working fine, I want to share my experience with the Json Service Orchestration Integration for Form Post so that others can also get benefit of this if they have the same requirements.

    Lanax, thanks to share the posts these have worked for me I will marked both of your response As Answer.

    For Service Request:

    1.        First create the Flat file schema to post the data as described in following post.

    http://www.quicklearn.com/blog/2013/08/30/biztalk-server-2013-support-for-restful-services-part-35/

    1.        Create a Map the will transform your Request message to JSON Service Form Post. Hierarchical Schema to a Name Value Pair as described in following post.

    https://code.msdn.microsoft.com/windowsdesktop/BizTalk-Mapper-Patterns-4041242c

    1.        Create a Custom Send Pipeline having the flat file assembler and Schema Document as of type crate in step 1.

    For Service Response.

    1.        Create the Flat file Schema that will receive the Response.
    2.        Create a Receive Pipeline that will Disassemble the flat file schema and having the document schema same as define in Step 4
    Monday, October 17, 2016 4:39 PM
  • Guys, one question, how can I assign the value in Name Value pair Map? I have created the Map the request that I send it is good, but in map here is a hardcoded value that I have to change in Orchestration? How can I do this, remember I have Name value Pair Schema so I cannot use the xpath.

    Thanks

    Thursday, October 20, 2016 7:19 PM
  • put this expression in Expression shape:

    xmlDoc.LoadXML("<ns0:HttpRequestBody xmlns:ns0='http://requestSample.FormValues'><FormValue><Id>username</Id><value>Username_1</value></FormValue><FormValue><Id>password</Id><value>Password_1</value></FormValue></ns0:HttpRequestBody>");

    This will solve your hard coded value problem


    When you see answers and helpful posts, please click Vote As Helpful , Propose As Answer , and/or Mark As Answer

    • Proposed as answer by har Wednesday, June 26, 2019 11:35 AM
    Wednesday, June 26, 2019 11:35 AM