.net WCF服务返回“;“坏的”;响应-客户端获取的数据与服务器发送的数据不同

.net WCF服务返回“;“坏的”;响应-客户端获取的数据与服务器发送的数据不同,.net,wcf,wsdl,.net,Wcf,Wsdl,我的WCF服务遇到了一个奇怪的问题 我可以提交一条消息,并返回结果。我遇到的问题是服务器显示什么作为响应,客户机得到不同的版本 无法更改客户端软件以使其正常工作。它基于WSDL契约,这是创建WCF服务的基础 更新: 我们在XML中使用的所有默认名称空间似乎都被出站数据上的新默认名称空间所覆盖 服务 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

我的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;
    }
(代码现在只是在模拟功能,直到我得到正确的响应。)

当我查看服务器上生成的XML或服务器上的对象时

服务器端的XML示例看起来是这样的-我可以将它序列化和反序列化到HCIM_IN_GetDemograhpics类型中,也可以从HCIM_反序列化,而不会出现任何问题或数据降级

XML/来自我期望的服务器的数据(未获取)

但是现在客户端中的结果对于每个属性都是null


有没有一种方法可以将字符串类型作为此WCF服务的输入/输出类型,其中连接设备不需要更改其绑定/代码(它们绑定到WSDL协定)。

此堆栈溢出问题回答了这个问题:

从WCF的WSDL(SOAP)生成时,我需要使用serializer命令:
svcutil QUPA_AR101102.wsdl/serializer:XmlSerializer/fault

WCF.NET默认情况下使用DataContractSerializer。您可以通过添加[XmlSerializerFormat()]注释来覆盖此项。 您可以使用/serializer:XmlSerializer开关生成注释,而不是将注释添加到生成的文件中

因此,在生成类时,请使用XMLSerializer而不是DataContract序列化程序:


svcutil QUPA_AR101102.wsdl/serializer:XmlSerializer/fault

您有wsdl链接吗?我必须精简wsdl,不允许共享完整内容(19000行)。有没有一种方法可以修改服务以返回XML而不是基于消息的a类型而不破坏契约?啊,HL7v3的乐趣…我很清楚!它似乎在所有由WSDL生成的WCF服务上都这样做-它无法识别默认名称空间,因此输出似乎已损坏
[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);

...
}
<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">
...
<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>
<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>
[System.Runtime.Serialization.DataContract(Namespace = "urn:hl7-org:v3")]