【问题标题】:Problem deserializing soap message on call back回拨时反序列化soap消息的问题
【发布时间】:2010-11-18 09:46:39
【问题描述】:

我正在实现一个由另一个服务回调的 WCF .NET 服务。
回调服务发回的soap消息如下

SOAP 消息

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"                
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
<ns1:getAccountBalance soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://service.company.x.y">
  <param0 xsi:type="xsd:string">123-K</param0>
  <param1 xsi:type="xsd:string">551003</param1>
  <param2 xsi:type="xsd:string">123</param2>
  <param3 xsi:type="xsd:string">1231</param3>
  <param4 xsi:type="xsd:string">ug</param4>
  <param5 xsi:type="xsd:string">x</param5>
  <param6 xsi:type="xsd:string">1.0</param6>
</ns1:getAccountBalance>
  </soapenv:Body>
</soapenv:Envelope>

接收消息的 WCF 合约

 [OperationContract(Action="")]
    AccountEnquiryResponse getAccountBalance(String param0, String param1, String param2, String param3, String param4, String param5, String param6);

服务实现

[ServiceBehavior(Namespace = "http://service.company.x.y")]
public class MyService:IService
{
    public AccountEnquiryResponse getAccountBalance(String param0, String param1, String param2, String param3, String param4, String param5, String param6)
    {
        return new AccountEnquiryResponse

问题

当回调返回时,WCF 服务无法反序列化 SOAP 消息参数 - 它们都是 null

有效的肥皂消息

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<getAccountBalance xmlns="http://service.company.x.y">
  <param0>123</param0>
  <param1>123</param1>
  <param2>uid</param2>
  <param3>pwd</param3>
  <param4>en</param4>
  <param5>ug</param5>
  <param6>1.0</param6>
</getAccountBalance>
</s:Body>
</s:Envelope>

我的结论

有效和无效的 SOAP 消息之间的区别在于属性 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 和 xsi:type="xsd:string 参数和 .NET 因为它们而无法正确反序列化对象。

这是真的吗?

我能做些什么来解决这个问题?

PS。回叫我的服务是用 JAVA 编写的第三方应用程序,我无法控制发送回我的应用程序的消息格式。

请指教

【问题讨论】:

  • 我发现了问题。不起作用的肥皂消息具有
  • 你有没有想过如何处理 ns1 命名空间问题?我有一种类似的感觉正在引起我的问​​题。
  • 是的。 .NET 允许您在接收消息之前或之后截取消息。请参阅代码示例 public class MMMessageInspector : IDispatchMessageInspector { public object AfterReceiveRequest(ref Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) { request = TransformMessage(request);返回空值; } public void BeforeSendReply(ref Message reply, object correlationState) { //do nothing } 然后你可以编写代码来删除 ns1

标签: c# java wcf web-services soap


【解决方案1】:

.Net 是否具有用于在 AccountEnquiryResponse 对象上设置命名空间的属性?这将解决您的两个问题。

如果您是服务器,那么客户端使用什么来生成它们的存根?你给他们一个wsdl吗?或将它们指向您正在运行的服务器?如果你给他们一个 wsdl,你是否使用相同的 wsdl 来生成你的服务接口?

这看起来真的就像两个不使用相同接口的方面。 XML 对完全限定名称非常挑剔。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多