我的WCF服务遇到了一个奇怪的问题。
我可以提交消息,并返回结果。我所拥有的问题是服务器显示为响应的问题,客户端获得了不同的版本。
无法更改客户端软件以使其正常工作。它基于WSDL合同,这是WCF服务的创建方式。
更新: 似乎我们在XML中使用的所有默认NameSpaces都被出站数据上的新默认值覆盖。
服务
[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 =&#34; http://schemas.datacontract.org/2004/07/HCIM.HL7v3.Objects.QUPA_AR101102"
我补充说:
[System.Runtime.Serialization.DataContract(Namespace = "urn:hl7-org:v3")]
到HCIM_IN_GetDemograhpicsResponse对象,但现在客户端的结果对于每个属性都是null。
有没有办法让字符串类型作为此WCF服务的输入/输出类型,其中连接设备不需要更改其绑定/代码(它们与WSDL协定绑定)。 / p>
答案 0 :(得分:1)
WCF .NET默认使用DataContractSerializer。您可以通过添加[XmlSerializerFormat()]注释来覆盖它。 您可以使用/ serializer:XmlSerializer开关生成注释,而不是将注释添加到生成的文件中。
因此,在生成类时,请使用XMLSerializer而不是DataContract序列化程序:
svcutil QUPA_AR101102.wsdl / serializer:XmlSerializer / fault
答案 1 :(得分:0)
这个Stack OVerflow问题回答了这个问题: .NET WCF serialization issues
从WCF的WSDL(SOAP)生成时,我需要使用serializer命令: svcutil QUPA_AR101102.wsdl / serializer:XmlSerializer / fault