WCF 服务返回 "bad" 响应 - 客户端获取的数据与服务器发送的数据不同
WCF Service returning "bad" response - Client gets data different than what the server sent
我的 WCF 服务遇到了一个奇怪的问题。
我可以提交消息,return 结果。我遇到的问题是服务器显示的响应,客户端得到不同的版本。
无法更改客户端软件以使其正常工作。它基于 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/Data 来自我期望的服务器(没有得到)
<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>
我已经尝试更改 return 类型、容器类型等。没有任何效果。我试图实现我的 WCF 服务以仅接受和 return XML 节点,但失败了。
数据正在正确发送,但 .NET 正在以某种方式更改它,我不确定 how/why。
传入消息的默认命名空间是: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_GetDemograhpicsResponse 对象,但现在客户端中的每个属性的结果都为 null。
有没有办法将字符串类型作为此 WCF 服务的 input/output 类型,其中连接设备不需要更改其 binding/code(它们绑定到 WSDL 合同) .
这个 Stack Overflow 问题回答了这个问题:
.NET WCF serialization issues
从 WCF 的 WSDL (SOAP) 生成时,我需要使用序列化程序命令:
svcutil QUPA_AR101102.wsdl /serializer:XmlSerializer /fault
WCF .NET 默认使用 DataContractSerializer。您可以通过添加 [XmlSerializerFormat()] 注释来覆盖它。
您可以使用 /serializer:XmlSerializer 开关生成,而不是将注释添加到生成的文件中。
因此在生成 类 时执行此操作以使用 XMLSerializer 而不是 DataContract 序列化程序:
svcutil QUPA_AR101102.wsdl /serializer:XmlSerializer /fault
我的 WCF 服务遇到了一个奇怪的问题。
我可以提交消息,return 结果。我遇到的问题是服务器显示的响应,客户端得到不同的版本。
无法更改客户端软件以使其正常工作。它基于 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/Data 来自我期望的服务器(没有得到)
<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>
我已经尝试更改 return 类型、容器类型等。没有任何效果。我试图实现我的 WCF 服务以仅接受和 return XML 节点,但失败了。
数据正在正确发送,但 .NET 正在以某种方式更改它,我不确定 how/why。
传入消息的默认命名空间是: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_GetDemograhpicsResponse 对象,但现在客户端中的每个属性的结果都为 null。
有没有办法将字符串类型作为此 WCF 服务的 input/output 类型,其中连接设备不需要更改其 binding/code(它们绑定到 WSDL 合同) .
这个 Stack Overflow 问题回答了这个问题: .NET WCF serialization issues
从 WCF 的 WSDL (SOAP) 生成时,我需要使用序列化程序命令: svcutil QUPA_AR101102.wsdl /serializer:XmlSerializer /fault
WCF .NET 默认使用 DataContractSerializer。您可以通过添加 [XmlSerializerFormat()] 注释来覆盖它。 您可以使用 /serializer:XmlSerializer 开关生成,而不是将注释添加到生成的文件中。
因此在生成 类 时执行此操作以使用 XMLSerializer 而不是 DataContract 序列化程序:
svcutil QUPA_AR101102.wsdl /serializer:XmlSerializer /fault