BizTalk JSON反序列化

时间:2015-06-30 22:00:07

标签: json xml rest biztalk biztalk-2013r2

我必须通过BizTalk连接REST服务。该服务返回JSON响应,如下所示。当BizTalk响应端口尝试解码JSON消息时,我收到有关JSON到XML转换的错误。发生此错误的原因是JSON消息中嵌入了HTML标记。

错误:

  

(执行响应(接收)管道失败:" Avansas.Paritus.Suggest.T.JSONReceive,Avansas.Paritus.Suggest.T,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 7b2984270a9ffd13"来源:" JSON解码器"发送端口:" Avansas.Ibrahim.Suggest.T.SendPort" URI:" api1.test.com/services/rest&# 34 ;;原因:解析值时遇到意外的字符:<。路径'',第0行,位置0.)

例如:

如下所示,响应消息在JSON中有一个标签元素。 Label元素有一个带有html标记的文本( City ),这就是BizTalk尝试将JSON转换为XML时出现错误的原因。我认为BizTalk尝试将JSON转换为图2,但我想将其转换为图3.

我该如何解决这个问题?

在没有任何架构的情况下,有没有办法在业务流程上进行passthru传输?

如图一

{
    "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"
        }
    ]
}

图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>

图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>

此外我的服务可以返回xml响应,当我尝试处理xml响应时,得到以下错误。

  

XML错误   执行响应(接收)管道时出现故障:&#34; Microsoft.BizTalk.DefaultPipelines.XMLReceive,Microsoft.BizTalk.DefaultPipelines,Version = 3.0.1.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35&#34;资料来源:&#34; XML反汇编程序&#34;发送端口:&#34; aaa.bbb.Suggest.T.SendPort&#34; URI:&#34; https://api1.test.com/services/rest&#34;原因:按消息类型&#34; html&#34;查找文档规范失败。验证正确部署的架构

响应xml如下所示

<?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>

1 个答案:

答案 0 :(得分:3)

使用此架构:

<?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>

这条管道:

JSON Pipeline

制作此消息:

<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>