locked
REST service JSON message RRS feed

  • Question

  • Now that I have created the REST service with the query parameter. The message I receive from the client, I need to convert in to JSON format. I know the list of columns that will be returned from client. So my question is

    1. Through REST service we receive a XML message? Because in the articles it is mentioned that it generates XML or JSON message

    2. do I need create a flat file schema Or a normal schema with all the columns as element. And do a mapping here. Convert them in JSON using the JSON encoder in the pipeline.

    3. Can this be done with without an Orchestration, because I am not sure what is the message type of the received message. Should I make the same schema which I created for sending the JSON message

    Thanks experts for helping me out. I really appreciate your help

    Sunday, June 5, 2016 11:43 AM

Answers

  • Now that I have created the REST service with the query parameter. The message I receive from the client, I need to convert in to JSON format. I know the list of columns that will be returned from client. So my question is

    1. Through REST service we receive a XML message? Because in the articles it is mentioned that it generates XML or JSON message

    2. do I need create a flat file schema Or a normal schema with all the columns as element. And do a mapping here. Convert them in JSON using the JSON encoder in the pipeline.

    3. Can this be done with without an Orchestration, because I am not sure what is the message type of the received message. Should I make the same schema which I created for sending the JSON message

    Thanks experts for helping me out. I really appreciate your help

    Hi Sid

    1. You can receive either JSON or XML from the client. All depends on your requirements. If you are receiving JSON from the client, you need to create a XML schema in BizTalk first using JSON schema wizard. The Receive Pipeline in that case should contain the JSON Decoder pipeline component. It will convert the JSON to XML format for you. If you receive XML content from client, you can use the XMLReceive pipeline itself.

    2. You don't really need to create a Flat-file schema. You must know the format of document that you will receive from the other org. What format do you receive currently - JSON or XML? If it's JSON, you can use the JSON Schema wizard to generate the XML equivalent for you - you will need the XML equivalent as BizTalk can only work with XML documents internally.

    Refer this example.

    If you want to send back JSON content to the client, you need the JSONEncoder pipeline component in your Send pipeline.

    3. It depends whether you need orchestration or not. But, you will know the messagetype of received message as the Receive Pipeline should contain two things if you are accepting JSON content-

    a) JSON Decoder - will convert JSON input to XML format (not needed if client sends XML)

    b) XML Disassembler - will parse the XML output from (a) and promote MessageType property. So, your orchestration can receive a typed XML message - the message type being the XSD schema you generate using the JSON schema wizard.

    You can refer this thread where similar discussion happened, has some helpful links-

    https://social.technet.microsoft.com/Forums/en-US/79c74031-7443-4fd5-a320-2a3b7db06083/warning-while-trying-to-pass-the-json-input-to-the-restfull-api?forum=biztalkr2adapters


    Thanks Arindam


    Sunday, June 5, 2016 11:49 AM
    Moderator
  • 1. REST is just a 'standard' on how to use the http URL and Verb.  The content can be anything you want, Xml, JSON, MIME, Binary, Flat Text...whatever.  So, yes, if that's what you want, but you should probably use JSON.

    2. No, you need to agree on a JSON format with the other team, no flat file involved.  The easiest way is to create a sample JSON first, then use the BizTalk Wizard to generate the xsd Schema.

    3. Maybe, maybe not.  An Orchestration isn't required for JSON*.  If you need an Orchestration for you actual business process, which has nothing to do with REST/JSON, then use one, there's nothing wrong with that.

    *Once the JSON message passes the Decoder, it's xml inside BizTalk.  That why you generate a Schema for it.

    • Marked as answer by Sid_2014 Monday, June 6, 2016 2:46 PM
    Sunday, June 5, 2016 12:15 PM
    Moderator
  • 1. Through REST service we receive a XML message? Because in the articles it is mentioned that it generates XML or JSON message

    It depends on the client and what format they agree upon to represent data. 

    In case of XML you don't need to do any decoding or dissembling, just have to use XML receive pipeline.

    If in case you receive JSON from the client, you will have to convert it into XML as in within BizTalk you need to follow XML format. For that you will need BizTalk XML schema for further processing. So Generate an XSD schema for JSON message and Create custom pipelines to process JSON messages.

    2. do I need create a flat file schema Or a normal schema with all the columns as element. And do a mapping here. Convert them in JSON using the JSON encoder in the pipeline.

    You don't need Flat file schema at all. I would advice you to have an agreement with business to accept either XML or JSON as agreed data format. 

    As mentioned by you that the client need response in JSON then you can use JSON Encoder pipeline component in your Send pipeline to transform the XML to JSON before sending.

    If you using BizTalk 2013 R2, you can use  2 new pipelines components for encoding and decoding JSON messages. Refer to links shared above.

    If you are BizTalk 2013, you would need to create your own custom component to encode and decode JSON. Refer: BIZTALK SERVER 2013 SUPPORT FOR RESTFUL SERVICES and Json, Send and Receive Pipelines for BizTalk Server

    3. Can this be done with without an Orchestration, because I am not sure what is the message type of the received message. Should I make the same schema which I created for sending the JSON message

    If you do not have any business logic to be implement then you will not be needing orchestration, yes you can always do away with orchestration.

    The JSON encoder and decoder Pipeline Components don’t use any Schemas for converting to/from JSON. They are easy to get up an running without any Disassemblers or Schemas. You would need a schema for JSON decoder component to work if you need to do some processing within BizTalk for which you need to convert JSON to XML.

    If your client wants JSON you just need a JSONPassThruTransmit pipeline to convert the XML message to JSON.

    Refer: https://blog.vertica.dk/2014/06/28/working-with-json-in-biztalk-server-2013-r2/

    For more understanding you can refer a consolidate page having lot of good articles which deals with RESTful services and JSON processing: BizTalk Server 2013: REST Support through WCF-WebHttp


    Rachit Sikroria (Microsoft Azure MVP)

    • Marked as answer by Sid_2014 Monday, June 6, 2016 2:46 PM
    Sunday, June 5, 2016 1:15 PM
    Moderator

All replies

  • Now that I have created the REST service with the query parameter. The message I receive from the client, I need to convert in to JSON format. I know the list of columns that will be returned from client. So my question is

    1. Through REST service we receive a XML message? Because in the articles it is mentioned that it generates XML or JSON message

    2. do I need create a flat file schema Or a normal schema with all the columns as element. And do a mapping here. Convert them in JSON using the JSON encoder in the pipeline.

    3. Can this be done with without an Orchestration, because I am not sure what is the message type of the received message. Should I make the same schema which I created for sending the JSON message

    Thanks experts for helping me out. I really appreciate your help

    Hi Sid

    1. You can receive either JSON or XML from the client. All depends on your requirements. If you are receiving JSON from the client, you need to create a XML schema in BizTalk first using JSON schema wizard. The Receive Pipeline in that case should contain the JSON Decoder pipeline component. It will convert the JSON to XML format for you. If you receive XML content from client, you can use the XMLReceive pipeline itself.

    2. You don't really need to create a Flat-file schema. You must know the format of document that you will receive from the other org. What format do you receive currently - JSON or XML? If it's JSON, you can use the JSON Schema wizard to generate the XML equivalent for you - you will need the XML equivalent as BizTalk can only work with XML documents internally.

    Refer this example.

    If you want to send back JSON content to the client, you need the JSONEncoder pipeline component in your Send pipeline.

    3. It depends whether you need orchestration or not. But, you will know the messagetype of received message as the Receive Pipeline should contain two things if you are accepting JSON content-

    a) JSON Decoder - will convert JSON input to XML format (not needed if client sends XML)

    b) XML Disassembler - will parse the XML output from (a) and promote MessageType property. So, your orchestration can receive a typed XML message - the message type being the XSD schema you generate using the JSON schema wizard.

    You can refer this thread where similar discussion happened, has some helpful links-

    https://social.technet.microsoft.com/Forums/en-US/79c74031-7443-4fd5-a320-2a3b7db06083/warning-while-trying-to-pass-the-json-input-to-the-restfull-api?forum=biztalkr2adapters


    Thanks Arindam


    Sunday, June 5, 2016 11:49 AM
    Moderator
  • 1. REST is just a 'standard' on how to use the http URL and Verb.  The content can be anything you want, Xml, JSON, MIME, Binary, Flat Text...whatever.  So, yes, if that's what you want, but you should probably use JSON.

    2. No, you need to agree on a JSON format with the other team, no flat file involved.  The easiest way is to create a sample JSON first, then use the BizTalk Wizard to generate the xsd Schema.

    3. Maybe, maybe not.  An Orchestration isn't required for JSON*.  If you need an Orchestration for you actual business process, which has nothing to do with REST/JSON, then use one, there's nothing wrong with that.

    *Once the JSON message passes the Decoder, it's xml inside BizTalk.  That why you generate a Schema for it.

    • Marked as answer by Sid_2014 Monday, June 6, 2016 2:46 PM
    Sunday, June 5, 2016 12:15 PM
    Moderator
  • 1. Through REST service we receive a XML message? Because in the articles it is mentioned that it generates XML or JSON message

    It depends on the client and what format they agree upon to represent data. 

    In case of XML you don't need to do any decoding or dissembling, just have to use XML receive pipeline.

    If in case you receive JSON from the client, you will have to convert it into XML as in within BizTalk you need to follow XML format. For that you will need BizTalk XML schema for further processing. So Generate an XSD schema for JSON message and Create custom pipelines to process JSON messages.

    2. do I need create a flat file schema Or a normal schema with all the columns as element. And do a mapping here. Convert them in JSON using the JSON encoder in the pipeline.

    You don't need Flat file schema at all. I would advice you to have an agreement with business to accept either XML or JSON as agreed data format. 

    As mentioned by you that the client need response in JSON then you can use JSON Encoder pipeline component in your Send pipeline to transform the XML to JSON before sending.

    If you using BizTalk 2013 R2, you can use  2 new pipelines components for encoding and decoding JSON messages. Refer to links shared above.

    If you are BizTalk 2013, you would need to create your own custom component to encode and decode JSON. Refer: BIZTALK SERVER 2013 SUPPORT FOR RESTFUL SERVICES and Json, Send and Receive Pipelines for BizTalk Server

    3. Can this be done with without an Orchestration, because I am not sure what is the message type of the received message. Should I make the same schema which I created for sending the JSON message

    If you do not have any business logic to be implement then you will not be needing orchestration, yes you can always do away with orchestration.

    The JSON encoder and decoder Pipeline Components don’t use any Schemas for converting to/from JSON. They are easy to get up an running without any Disassemblers or Schemas. You would need a schema for JSON decoder component to work if you need to do some processing within BizTalk for which you need to convert JSON to XML.

    If your client wants JSON you just need a JSONPassThruTransmit pipeline to convert the XML message to JSON.

    Refer: https://blog.vertica.dk/2014/06/28/working-with-json-in-biztalk-server-2013-r2/

    For more understanding you can refer a consolidate page having lot of good articles which deals with RESTful services and JSON processing: BizTalk Server 2013: REST Support through WCF-WebHttp


    Rachit Sikroria (Microsoft Azure MVP)

    • Marked as answer by Sid_2014 Monday, June 6, 2016 2:46 PM
    Sunday, June 5, 2016 1:15 PM
    Moderator