我正在将旧版 Web 服务转换为 WCF 服务。前端应用程序当前正在使用此服务。但到目前为止,前端有意使用新的 WCF 服务,因此我们计划将请求从 IIS 重新路由到我们的新服务。这里的问题是新的 WCF 服务应该能够处理旧的输入请求,并且应该能够以完全相同的格式发回响应。
我在处理输入请求时没有遇到任何问题,但我在尝试以旧格式返回消息时遇到了问题。我当前的服务以以下格式返回 SoapResponse(我没有使用任何消息合同/DataContracts,因为我使用的是旧遗留代码中使用的相同返回类型和输入参数):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserCheckResponse xmlns="Abc.SomeNamespace">
<UserCheckResult a:Direction="Response" a:Purpose="UserCheck" xmlns:a="Abc.SomeNamespace">
<a:KV a:Key="TraceID" a:Value="546546565" />
<a:KV a:Key="Response" a:Value="78954" />
<a:KV a:Key="UserVerified" a:Value="N" />
<a:KV a:Key="TryAgain" a:Value="Y" />
<a:KV a:Key="DataSource" a:Value="NA" />
</UserCheckResult>
</UserCheckResponse>
我希望它看起来像下面(我不希望响应中的 UserCheckResult 节点,而是我想要直接在 UserCheckResponse 节点下的键值对):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserCheckResponse a:Direction="Response" a:Purpose="UserCheck" xmlns:a="Abc.SomeNamespace">
<a:KV a:Key="TraceID" a:Value="546546565" />
<a:KV a:Key="Response" a:Value="78954" />
<a:KV a:Key="UserVerified" a:Value="N" />
<a:KV a:Key="TryAgain" a:Value="Y" />
<a:KV a:Key="DataSource" a:Value="NA" />
</UserCheckResponse>