考虑以下简化的 XML 模式集合
CREATE XML SCHEMA COLLECTION CD.AcceptMessageSchema AS '
<xs:schema xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit"
xmlns:ns1="http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit"
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
targetNamespace="http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="AcceptMessage">
<xs:complexType>
<xs:sequence>
<xs:element name="MessagePayload" type="xs:string"/>
<xs:element name="PatientIdentifiers">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="ID" type="ID">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
和以下存储过程定义
create procedureSubmit.AcceptMessage_DEV @AcceptMessage xml(CD.AcceptMessageSchema)
as
Insert into blah...
...stored proc guts go here...
您会注意到单个参数被定义为与 Schema Collection 相关联。我的假设是,鉴于与 SchemaCollection 的关联,您可以通过发送如下内容来调用存储过程:
<AcceptMessage xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit" xmlns:biztalk="http://InteriorHealth.BizTalk.CDX.Schemas.SQLSubmit.AcceptMessage" xmlns:ns0="http://microsoft.com/HealthCare/HL7/2X" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessagePayload>
<![CDATA[somepayloaddata]]>
</MessagePayload>
<PatientIdentifiers>
<ID OID="2.16.840.1.113883.4.50" Value="3454545" AssigningAuthorityName="Patient Health Number" />
<ID OID="2.16.840.1.113883.3.277.1.73" Value="4545454" AssigningAuthorityName="Patient EMR Number" />
</PatientIdentifiers>
</AcceptMessage>
它可以通过 WCF-SQL 发送端口工作。
奇怪的是,如果我在 SSMS 中调用存储过程:
EXEC Submit.AcceptMessage @AcceptMessage = ' <AcceptMessage xmlns="http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit" xmlns:biztalk="http://InteriorHealth.BizTalk.CDX.Schemas.SQLSubmit.AcceptMessage" xmlns:ns0="http://microsoft.com/HealthCare/HL7/2X" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessagePayload>
<![CDATA[somepayloaddata]]>
</MessagePayload>
<PatientIdentifiers>
<ID OID="2.16.840.1.113883.4.50" Value="3454545" AssigningAuthorityName="Patient Health Number" />
<ID OID="2.16.840.1.113883.3.277.1.73" Value="4545454" AssigningAuthorityName="Patient EMR Number" />
</PatientIdentifiers>
</AcceptMessage>';
它工作得很好,但是通过 WCF-SQL 通过网络发送它我得到了错误:
The start element with name "MessagePayload" and namespace "http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit" was unexpected. Please ensure that your input XML conforms to the schema for the operation.
这与我应用 XML Schema 集合并像这样定义存储过程之前发生的事情是一样的:
create procedureSubmit.AcceptMessage_DEV
@MessagePayload xml,
@PatientIdentifiers xml
as
如果我要像上面那样发送请求,它会给出错误:
The start element with name "ID" and namespace "http://schemas.microsoft.com/Sql/2008/05/Procedures/Submit" was unexpected. Please ensure that your input XML conforms to the schema for the operation.
因为它不知道如何处理<ID>
元素内部的<PatientIdentifiers>
元素。
我之前将所有参数数据包装在 CDATA 标记中并且它有效,但如果它有效,我希望添加模式验证。
那么这是否意味着在调用 WCF-SQL 时,我基本上必须对参数元素内的所有内容进行 CDATA,或者我缺少什么?
此外,这是一个仅消息传递的解决方案,没有编排。
如何将嵌套的 XML 发送到 SQL 存储过程中以解析它并将数据插入表中?