Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BizTalk JSON Deserialize

I have to connect a REST service via BizTalk. The service returns a JSON response as shown below. When the BizTalk response port tries to decode the JSON message I get an error about JSON to XML conversion. This error happen because of embedded HTML tags in the JSON Message.

Error:

(There was a failure executing the response(receive) pipeline: "Avansas.Paritus.Suggest.T.JSONReceive, Avansas.Paritus.Suggest.T, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b2984270a9ffd13" Source: "JSON decoder" Send Port: "Avansas.Ibrahim.Suggest.T.SendPort" URI: "api1.test.com/services/rest"; Reason: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. )

For Example:

As below response message has a label element in JSON. Label element has a text with html tag (City) that's why when BizTalk tries to convert JSON to XML I get an error. I think BizTalk tries to convert JSON as figure 2 but I want to convert it as figure 3.

How can I solve this issue?

Is there any way to passthru transmit on orchestration without any schema?

Figure1

{
    "suggestion": [
        {
            "id": "[31 31 31 30 30 39]",
            "label": "Global <b>City</b> 2. Etap Global <b>Cıty</b> ",
            "value": "Global <b>City</b> 2. Etap Villaları "
        },
        {
            "id": "[39 33 36 32 35 36]",
            "label": "<b>City</b> Aqua Villas Sk.  Kuşadası Aydın",
            "value": "<b>City</b> Aqua Villas Sk.  Kuşadası Aydın"
        }
    ]
}

Figure 2:

<root>
    <suggestion>
        <id>[31 31 31 30 30 39]</id>
        <label>Global 
            <b>City</b> 2. Etap Global 
            <b>Cıty</b>
        </label>
        <value>Global 
            <b>City</b> 2. Etap Villaları 
        </value>
    </suggestion>
    <suggestion>
        <id>[39 33 36 32 35 36]</id>
        <label>
            <b>City</b> Aqua Villas Sk.  Kuşadası Aydın
        </label>
        <value>
            <b>City</b> Aqua Villas Sk.  Kuşadası Aydın
        </value>
    </suggestion>
</root>

Figure 3:

<root>
    <suggestion>
        <id>[31 31 31 30 30 39]</id>
        <label>Global 
            &lt;b&gt;City&lt;/b&gt; 2. Etap Global 
            &lt;b&gt;Cıty&lt;/b&gt;
        </label>
        <value>Global 
            &lt;&gt;City&lt;/b&gt; 2. Etap Villaları 
        </value>
    </suggestion>
    <suggestion>
        <id>[39 33 36 32 35 36]</id>
        <label>
            &lt;b&gt;City&lt;/b&gt; Aqua Villas Sk.  Kuşadası Aydın
        </label>
        <value>
            &lt;b&gt;City&lt;/b&gt; Aqua Villas Sk.  Kuşadası Aydın
        </value>
    </suggestion>
</root>

Also my service can be return xml response and when i try to handle xml response a get an below error.

XML Error There was a failure executing the response(receive) pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Send Port: "aaa.bbb.Suggest.T.SendPort" URI: "https://api1.test.com/services/rest" Reason: Finding the document specification by message type "html" failed. Verify the schema deployed properly

And response xml as shown below

<?xml version="1.0" encoding="UTF-8"?>
<suggestions>
   <suggestion>
      <id>111011</id>
      <label>Global &lt;b&gt;Cıty&lt;/b&gt; 1. Etap Vıllaları Sokak</label>
      <value>Global Cıty 1. Etap Vıllaları Sokak</value>
   </suggestion>
   <suggestion>
      <id>111009</id>
      <label>Global &lt;b&gt;Cıty&lt;/b&gt; 2. Etap Vıllaları Sokak</label>
      <value>Global Cıty 2. Etap Vıllaları Sokak</value>
   </suggestion>
</suggestions>
like image 810
ibrahimsen Avatar asked Oct 20 '22 08:10

ibrahimsen


1 Answers

Using this schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://BizTalk_Server_Project1.JSONSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="suggestion">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" name="id" type="xs:string" />
              <xs:element minOccurs="0" name="label" type="xs:string" />
              <xs:element minOccurs="0" name="value" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

And this pipeline:

JSON Pipeline

Produces this message:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.JSONSchema1">
  <suggestion>
    <id>[31 31 31 30 30 39]</id>
    <label>Global &lt;b&gt;City&lt;/b&gt; 2. Etap Global &lt;b&gt;Cıty&lt;/b&gt; </label>
    <value>Global &lt;b&gt;City&lt;/b&gt; 2. Etap Villaları </value>
  </suggestion>
  <suggestion>
    <id>[39 33 36 32 35 36]</id>
    <label>&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk.  Kuşadası Aydın</label>
    <value>&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk.  Kuşadası Aydın</value>
  </suggestion>
</ns0:Root>
like image 143
Dan Field Avatar answered Oct 21 '22 23:10

Dan Field