【问题标题】:BizTalk map not working when namespace prefix is missing缺少命名空间前缀时,BizTalk 映射不起作用
【发布时间】:2017-12-03 16:48:00
【问题描述】:

我无法让我的 BizTalk 地图在信封分批后处理邮件。该地图似乎需要命名空间前缀,但分批的消息没有前缀。如果我向根添加前缀,例如 <ns0:Encounter xmlns:ns0="http://hl7.org/fhir/Encounters">,那么当我在 Visual Studio 中使用测试地图时,地图可以正常工作。如果没有前缀,我仍然可以从映射中获得输出,但只有常量被映射到目标架构中,没有任何内容从源架构中映射。

我收到每个映射元素的以下错误消息

“错误btm1044:输入验证错误:'value'属性未声明。”

我已尝试将 elementFormDefault 的值从不合格更改为合格,如单独帖子中所建议的那样,但仍然没有运气。

信封分批后,我最终得到以下 XML。请注意,没有命名空间前缀。 如果我停止发送端口并查看已分批的消息,则 MessageType 为 http://hl7.org/fhir/Encounters#Encounter

  <?xml version="1.0" encoding="utf-8"?>
<Encounter xmlns="http://hl7.org/fhir/Encounters">
    <id value="ac34e2c2-6080-4c46-9ec5-d7340a7c4177" />
    <extension url="https://api-foo.org/documents/fhir/extensions/encounter-facility">
        <valueString value="foo" />
    </extension>
    <extension url="https://api-foo.org/documents/fhir/extensions/encounter-service">
        <valueString value="fooo" />.......

我的架构是这样的

  <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://hl7.org/fhir/Encounters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://hl7.org/fhir/Encounters" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Encounter">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id">
          <xs:complexType>
            <xs:attribute name="value" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="extension">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" name="valueInteger">
                <xs:complexType>
                  <xs:attribute name="value" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="valueString">
                <xs:complexType>
                  <xs:attribute name="value" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="url" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element> ............

有没有办法让地图/模式按原样处理消息,或者让分批的消息具有前缀。

我还有一个自定义管道组件,用于在分批之前更改传入消息的命名空间。我不确定这是否会导致下面的代码出现问题。

public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
    {
        if (Enabled)
        {
            try
            {
                IBaseMessagePart bodyPart = inmsg.BodyPart;

                if (bodyPart != null)
                {
                    string json;

                    using (Stream originalDataStream = bodyPart.GetOriginalDataStream())
                    {
                        if (originalDataStream != null)
                        {
                            //Read the json message
                            using (TextReader tr = new StreamReader(originalDataStream))
                            {
                                json = tr.ReadToEnd();
                            }

                            //Use FHIR-NET-API to create a FHIR resource from the json
                            Hl7.Fhir.Serialization.ResourceReader resourceReader = new Hl7.Fhir.Serialization.ResourceReader(FhirJsonParser.CreateFhirReader(json), ParserSettings.Default);

                            //switch the namespace
                            var doc = XElement.Parse(Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(resourceReader.Deserialize()));

                            XNamespace toNs = Namespace;
                            doc.DescendantsAndSelf().Attributes().Where(a => a.IsNamespaceDeclaration).Remove();
                            var ele = doc.DescendantsAndSelf();
                            foreach (var el in ele)
                                el.Name = toNs + el.Name.LocalName;

                            //Create the new BizTalk message
                            var memoryStream = new MemoryStream();
                            doc.Save(memoryStream);
                            //  memoryStream.Write(resourceXmlBytes, 0, resourceXmlBytes.Length);
                            memoryStream.Position = 0;
                            inmsg.BodyPart.Data = memoryStream;
                        }
                    }
                }

                return inmsg;
            }
            catch (Exception e)
            {
                GenericEventLogger.LogEvent(
                ExceptionSource,
                String.Format("An exception [{0}] occured in [{1}( )]. \n\nMessage: \n{2} \n\nStack Trace: \n{3}",
                                e.GetType().Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName,
                                e.Message,
                                e.StackTrace),
                EventLogEntryType.Error,
                999);
                throw;
            }
        }

        return inmsg;
    }

这是信封架构

    <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://hl7.org/fhir/Encounters" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://hl7.org/fhir/Encounters" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo is_envelope="yes" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Bundle">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo body_xpath="/*[local-name()='Bundle' and namespace-uri()='http://hl7.org/fhir/Encounters']/*[local-name()='entry' and namespace-uri()='http://hl7.org/fhir/Encounters']/*[local-name()='resource' and namespace-uri()='http://hl7.org/fhir/Encounters']" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="total">
          <xs:complexType>
            <xs:attribute name="value" type="xs:unsignedByte" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="entry">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="resource">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Encounter">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:any />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

【问题讨论】:

  • 你的命名空间管道组件在接收管道的哪一部分?您使用什么方法分批消息?使用信封模式? (如果是,请显示其架构)如果您将地图从端口中取出,那么消息上下文中的消息类型是什么?管道中是否还有 XML 验证器? (因为该错误看起来来自该地图而不是地图,或者是您在测试地图时从 Visual Studio 得到的错误?)
  • 您使用的是 BizTalk HL7 反汇编程序吗?
  • 在管道组件中,我使用 HL7 FHIR 库将传入的 json 转换为 XML,然后在 Execute 方法中更改命名空间。管道组件位于管道的解码部分。标准 XML 反汇编器组件位于管道的 Disassemble 部分。没有使用其他组件。我将使用信封架构和其他请求的信息更新帖子的主要内容。
  • 进行了几次更新以发布包含@Dijkgraaf 要求的信息

标签: biztalk biztalk-2013


【解决方案1】:

由于您使用的是 FHIR 的 JSON 表示,所以第一个问题应该是您是否甚至需要使用 Xml 命名空间。

在 BizTalk 中处理本机 JSON 内容时,我的建议是在所有 Xml 处理中使用 Empty Namespace。

您可以参考这篇 Wiki 文章了解更多详情:BizTalk: Simplify BizTalk Dev by Using the Empty Namespace

【讨论】:

  • 谢谢@Johns-305 我会看看这个和你对我的另一个线程的回复,并做出正确的设计更改。
  • 对于其他阅读的人,在此线程link 上有更多关于同一问题的信息。 @Johns-305 提供解决方案的其他链接。
  • 我切换到在我的信封和 msg 架构上使用空命名空间,并在 XmlDisassembler 中指定架构,如上面链接中所述,我的应用程序现在按预期运行。再次感谢您的帮助。 @Johns-305 - 文章提到“社区命名空间删除的 Visual Studio 解决方案”即将推出。这个 VS 解决方案可以下载吗?
  • @David 抱歉,这是一个错误,已更正。示例项目中只有已编译的程序集可用。
猜你喜欢
  • 1970-01-01
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 2012-11-27
相关资源
最近更新 更多