【发布时间】:2015-02-05 03:05:50
【问题描述】:
我的 WCF 服务出现了一个奇怪的问题。
我可以提交消息并返回结果。我遇到的问题是服务器显示的响应,客户端得到不同的版本。
无法更改客户端软件以使其正常工作。它基于 WSDL 契约,而 WCF 服务正是基于该契约创建的。
更新: 似乎我们在 XML 中使用的所有默认名称空间都被出站数据上的新默认名称空间覆盖了。
服务
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[WebServiceBindingAttribute(Name = "QUPA_AR101102_Binding", Namespace = "urn:hl7-org:v3")]
GetDemographicsResponse1 IQUPA_AR101102.HCIM_IN_GetDemographics(Message request)
{
HCIM.HIALServices.QUPA_AR101102_Service service = new HIALServices.QUPA_AR101102_Service();
XmlDocument doc = new XmlDocument();
doc.LoadXml(request.GetReaderAtBodyContents().ReadOuterXml());
HCIM.HIALMessaging.GetDemographics gd = new HIALMessaging.GetDemographics(System.Web.HttpContext.Current);
XmlNode gdr = gd.HIALRequest(doc);
//These 2 lines produce the same data on the server, but the client sees this totally different.
//HCIM.HL7v3.Objects.QUPA_AR101102.HCIM_IN_GetDemographicsResponse response = this.getMessageObject<HCIM.HL7v3.Objects.QUPA_AR101102.HCIM_IN_GetDemographicsResponse>(gdr.OuterXml, "urn:hl7-org:v3");
HCIM_IN_GetDemographicsResponse1 r1 = new HCIM_IN_GetDemographicsResponse1(gd.wcfObjectResponse as HCIM.HL7v3.Objects.QUPA_AR101102.HCIM_IN_GetDemographicsResponse);
//the above line is a serialized version of the XML - I just packaged it up to` test
return r1;
}
合同
[ServiceContract(Namespace = "urn:hl7-org:v3")]
public interface IQUPA_AR101102
{
[OperationContract(Name = "HCIM_IN_GetDemographics", Action = "urn:hl7-org:v3/QUPA_IN101101")]
HCIM_IN_GetDemographicsResponse1 HCIM_IN_GetDemographics(Message request);
...
}
(代码现在只是在模拟功能,直到我得到正确的响应。)
当我查看在服务器上生成的 XML 或存在于服务器上的对象时。
服务器端的 XML 示例如下所示 - 我可以在 HCIM_IN_GetDemograhpics 类型之间对其进行序列化和反序列化,而不会出现任何问题或数据降级。
来自服务器的 XML/数据我期待(没有得到)
<HCIM_IN_GetDemographicsResponse xmlns="urn:hl7-org:v3">
<id root="2.16.840.1.113883.3.51.1.1.1" extension="404002d6-3978-413d-a49d-b11e240bbf26" />
<creationTime value="20150204185920" />
<versionCode code="V3PR1" />
<interactionId root="2.16.840.1.113883.3.51.1.1.2" extension="HCIM_IN_GetDemographicsResponse" />
<processingCode code="P" />
<processingModeCode code="T" />
<acceptAckCode code="NE" />
<receiver typeCode="RCV">
...
当我的客户收到这封邮件时,它会变得完全不同。
我收到的 XML 格式的数据
<HCIM_IN_GetDemographicsResponse xmlns="urn:hl7-org:v3" xmlns:a="http://schemas.datacontract.org/2004/07/HCIM.HL7v3.Objects.QUPA_AR101102" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:acceptAckCode>
<a:nullFlavor>NI</a:nullFlavor>
<a:nullFlavorSpecified>false</a:nullFlavorSpecified>
<a:code>NE</a:code>
<a:codeSystem i:nil="true" />
<a:codeSystemName i:nil="true" />
<a:codeSystemVersion i:nil="true" />
<a:displayName i:nil="true" />
<a:originalText i:nil="true" />
<a:qualifier i:nil="true" />
<a:translation i:nil="true" />
</a:acceptAckCode>
<a:creationTime>
<a:nullFlavor>NI</a:nullFlavor>
<a:nullFlavorSpecified>false</a:nullFlavorSpecified>
<a:value>20150204185920</a:value>
</a:creationTime>
<a:id>
<a:nullFlavor>NI</a:nullFlavor>
<a:nullFlavorSpecified>false</a:nullFlavorSpecified>
<a:assigningAuthorityName i:nil="true" />
<a:displayable>false</a:displayable>
<a:displayableSpecified>false</a:displayableSpecified>
<a:extension>404002d6-3978-413d-a49d-b11e240bbf26</a:extension>
<a:root>2.16.840.1.113883.3.51.1.1.1</a:root>
</a:id>
<a:interactionId>
<a:nullFlavor>NI</a:nullFlavor>
<a:nullFlavorSpecified>false</a:nullFlavorSpecified>
<a:assigningAuthorityName i:nil="true" />
<a:displayable>false</a:displayable>
<a:displayableSpecified>false</a:displayableSpecified>
<a:extension>HCIM_IN_GetDemographicsResponse</a:extension>
<a:root>2.16.840.1.113883.3.51.1.1.2</a:root>
</a:interactionId>
<a:nullFlavor i:nil="true" />
...
当前网络配置:
<bindings>
<basicHttpBinding>
<!-- Secure Bindings -->
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
<binding name="httpBinding">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!--Synchronous Services-->
<!--Get Demographics/FindCandidates/GetRelatedIdentifiers Service-->
<service name="HCIM.Services.Synchronous.QUPA_AR101102" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="HCIM.Services.Synchronous.Contracts.IQUPA_AR101102"></endpoint>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpBinding" contract="HCIM.Services.Synchronous.Contracts.IQUPA_AR101102" />
</service>
Cut-Down WSDL 原文为 19,000 行。具有 xsd:anyType 的元素指向架构中的具体元素。一位客户对此进行了修改,以便他们可以在该部分中使用 XML。如果我能让这个 WCF 与这样的 WSDL 一起工作就足够了。
<wsdl:types>
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="urn:hl7-org:v3" xmlns="urn:hl7-org:v3" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:hl7="urn:hl7-org:v3">
<xs:element name="GetDemographics" type="xsd:anyType"/>
<xs:element name="GetDemographicsResponse" type="xsd:anyType"/>
<xs:element name="FindCandidates" type="xsd:anyType"/>
<xs:element name="FindCandidatesResponse" type="xsd:anyType"/>
<xs:element name="GetRelatedIdentifiers" type="xsd:anyType"/>
<xs:element name="GetRelatedIdentifiersResponse" type="xsd:anyType"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetDemographicsSoapIn">
<wsdl:documentation>HCIM Get Person Demographics Query (localized QUPA_IN101101) </wsdl:documentation>
<wsdl:part name="body" element="tns:GetDemographics"/>
</wsdl:message>
<wsdl:message name="GetDemographicsSoapOut">
<wsdl:documentation>HCIM Get Person Demographics Response (localized QUPA_IN101102)</wsdl:documentation>
<wsdl:part name="body" element="tns:GetDemographicsResponse"/>
</wsdl:message>
<wsdl:message name="FindCandidatesSoapIn">
<wsdl:documentation>HCIM Find Candidates Query (localized QUPA_IN101103) </wsdl:documentation>
<wsdl:part name="body" element="tns:FindCandidates"/>
</wsdl:message>
<wsdl:message name="FindCandidatesSoapOut">
<wsdl:documentation>HCIM Find Candidates Response (localized QUPA_IN101104)</wsdl:documentation>
<wsdl:part name="body" element="tns:FindCandidatesResponse"/>
</wsdl:message>
<wsdl:message name="GetRelatedIdentifiersSoapIn">
<wsdl:documentation>HCIM Get Related Identifiers Query (localized QUPA_IN101105) </wsdl:documentation>
<wsdl:part name="body" element="tns:GetRelatedIdentifiers"/>
</wsdl:message>
<wsdl:message name="GetRelatedIdentifiersSoapOut">
<wsdl:documentation>HCIM Get Related Identifers Response (localized QUPA_IN101106)</wsdl:documentation>
<wsdl:part name="body" element="tns:GetRelatedIdentifiersResponse"/>
</wsdl:message>
<wsdl:portType name="QUPA_AR101102_PortType">
<wsdl:operation name="GetDemographics">
<wsdl:input message="tns:GetDemographicsSoapIn"/>
<wsdl:output message="tns:GetDemographicsSoapOut"/>
</wsdl:operation>
<wsdl:operation name="FindCandidates">
<wsdl:input message="tns:FindCandidatesSoapIn"/>
<wsdl:output message="tns:FindCandidatesSoapOut"/>
</wsdl:operation>
<wsdl:operation name="GetRelatedIdentifiers">
<wsdl:input message="tns:GetRelatedIdentifiersSoapIn"/>
<wsdl:output message="tns:GetRelatedIdentifiersSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QUPA_AR101102_Binding" type="tns:QUPA_AR101102_PortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetDemographics">
<soap:operation soapAction="urn:hl7-org:v3/QUPA_IN101101"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="FindCandidates">
<soap:operation soapAction="urn:hl7-org:v3/QUPA_IN101103"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetRelatedIdentifiers">
<soap:operation soapAction="urn:hl7-org:v3/QUPA_IN101105"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
我已尝试更改返回类型、容器类型等。没有任何效果。我尝试实现我的 WCF 服务以仅接受和返回 XMLNodes,但失败了。
数据正在正确发送,但 .NET 以某种方式对其进行了更改,我不确定如何/为什么。
传入消息的默认命名空间为:urn:hl7-org:v3 正在发送的输出使用了错误的命名空间:xmlns:a="http://schemas.datacontract.org/2004/07/HCIM.HL7v3.Objects.QUPA_AR101102"
我补充说:
[System.Runtime.Serialization.DataContract(Namespace = "urn:hl7-org:v3")]
到 HCIM_IN_GetDemographicsResponse 对象,但现在客户端中的结果对于每个属性都是空的。
有没有办法将字符串类型作为此 WCF 服务的输入/输出类型,其中连接设备不需要更改其绑定/代码(它们绑定到 WSDL 合同)。
【问题讨论】:
-
你有 wsdl 链接吗?
-
我必须精简 WSDL,不允许共享全部内容(19000 行长)。有没有办法在不破坏合同的情况下修改服务以返回 XML 而不是基于 Message 的类型?
-
啊,HL7v3的乐趣……我很清楚!
-
它似乎对从 WSDL 生成的所有 WCF 服务执行此操作 - 它无法识别默认命名空间,因此输出似乎已损坏