Java WCF:请求对象中另一对象类型的一个属性变为NULL

Java WCF:请求对象中另一对象类型的一个属性变为NULL,java,.net,wcf,web-services,Java,.net,Wcf,Web Services,我有带ws和basic绑定的WCF服务。从.Net客户端可以很好地工作,但当我从Java客户端调用相同的方法时,请求对象中的critera属性为NULL,尽管从wireshark中我可以看到数据正在到来。对于.Net,它使用来自网页的GET,但对于Java,它使用POST。不仅如此,如果在OperationContext中转到RequestMessage,我还可以看到xml 来自.NET客户端的请求消息: RequestMessage {<s:Envelope xmlns:s="http

我有带ws和basic绑定的WCF服务。从.Net客户端可以很好地工作,但当我从Java客户端调用相同的方法时,请求对象中的critera属性为NULL,尽管从wireshark中我可以看到数据正在到来。对于.Net,它使用来自网页的GET,但对于Java,它使用POST。不仅如此,如果在OperationContext中转到RequestMessage,我还可以看到xml

来自.NET客户端的请求消息:

RequestMessage  {<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://mcac83101cj.us.maritz.net/CouponService/CouponService.svc</To>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ICouponService/GetOrderByOrderId</Action>
  </s:Header>
  <s:Body>
    <GetOrderByOrderId xmlns="http://tempuri.org/">
      <orderRequest xmlns:a="http://schemas.datacontract.org/2004/07/CLinkService.Messages" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <AccessToken xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase">c2bf6e1e-e6fd-4930-8a9e-da9d918bbdc4</AccessToken>
        <Action xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase">Read</Action>
        <ClientTag xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase">Maritz@$0</ClientTag>
        <LoadOptions i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
        <RequestId xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase">93358933-7965-442f-bf38-9946ecfb3213</RequestId>
        <Version i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase" />
        <a:Criteria xmlns:b="http://schemas.datacontract.org/2004/07/CLinkService.Criteria">
          <b:DealerCode i:nil="true" />
          <b:Language i:nil="true" />
          <b:SortExpression i:nil="true" />
          <b:UserName i:nil="true" />
          <b:Xslt>MPS</b:Xslt>
          <b:OrderId>11</b:OrderId>
        </a:Criteria>
        <a:Order i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/CLinkService.Dto" />
      </orderRequest>
    </GetOrderByOrderId>
  </s:Body>
</s:Envelope>}  System.ServiceModel.Channels.Message {System.ServiceModel.Channels.BufferedMessage}
请求消息{ http://mcac83101cj.us.maritz.net/CouponService/CouponService.svc http://tempuri.org/ICouponService/GetOrderByOrderId c2bf6e1e-e6fd-4930-8a9e-da9d918bbdc4 阅读 马里茨:$0 93358933-7965-442f-bf38-9946ecfb3213 议员 11 }System.ServiceModel.Channels.Message{System.ServiceModel.Channels.BufferedMessage} 来自JAVA客户端的请求消息:

RequestMessage  {<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://mcac83101cj.us.maritz.net/CouponService/CouponService.svc</To>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ICouponService/GetOrderByOrderId</Action>
  </s:Header>
  <S:Body>
    <ns6:GetOrderByOrderId 
    xmlns:ns7="http://schemas.microsoft.com/2003/10/Serialization/" 
    xmlns:ns6="http://tempuri.org/" 
    xmlns:ns5="http://schemas.datacontract.org/2004/07/CLinkService.Dto" 
    xmlns:ns4="http://schemas.datacontract.org/2004/07/CLinkService.Messages" 
    xmlns:ns3="http://schemas.datacontract.org/2004/07/CLinkService.Criteria" 
    xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" 
    xmlns="http://schemas.datacontract.org/2004/07/CLinkService.MessageBase">
      <ns6:orderRequest>
        <Action>Read</Action>
        <ClientTag>Maritz@$0</ClientTag>
        <RequestId>200</RequestId>
        <ns3:OrderCriteria>
          <ns3:DealerCode>B0000</ns3:DealerCode>
          <ns3:Language>FR</ns3:Language>
          <ns3:Xslt>MPS</ns3:Xslt>
          <ns3:OrderId>9</ns3:OrderId>
        </ns3:OrderCriteria>
        <ns5:OrderDto>
          <ns5:DealerCode>B0000</ns5:DealerCode>
          <ns5:Language>FR</ns5:Language>
          <ns5:OrderId>11</ns5:OrderId>
        </ns5:OrderDto>
      </ns6:orderRequest>
    </ns6:GetOrderByOrderId>
  </S:Body>
</S:Envelope>}  System.ServiceModel.Channels.Message {System.ServiceModel.Channels.BufferedMessage}
请求消息{ http://mcac83101cj.us.maritz.net/CouponService/CouponService.svc http://tempuri.org/ICouponService/GetOrderByOrderId 阅读 马里茨:$0 200 B0000 FR 议员 9 B0000 FR 11 }System.ServiceModel.Channels.Message{System.ServiceModel.Channels.BufferedMessage} 服务器的Web.Config如下所示:

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="CLinkService.CouponServiceBehavior" name="CLinkService.ServiceImplementations.CouponService">
        <endpoint name="wsHttpBinding" address="secure" binding="wsHttpBinding" bindingConfiguration="wsBindingAction" contract="CLinkService.ServiceContracts.ICouponService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint name="basicHttpBinding" address="" binding="basicHttpBinding" bindingConfiguration="basicBindingAction" contract="CLinkService.ServiceContracts.ICouponService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CLinkService.CouponServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="wsBindingAction" transactionFlow="false" sendTimeout="00:30:00" receiveTimeout="00:30:00" maxReceivedMessageSize="524288" maxBufferPoolSize="524288">
          <reliableSession enabled="true"/>
          <security mode="None">
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="basicBindingAction" sendTimeout="00:30:00" receiveTimeout="00:30:00" maxReceivedMessageSize="524288" maxBufferPoolSize="524288">
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

您的.NET客户端可能正在发出:条件的默认值。可以通过使用EmitDefaultValue=false注释DataMember来抑制此行为:-

[DataMember(EmitDefaultValue = false)]
还可以看看这篇MSDN文章:-
不,事实并非如此。当客户端调用GetOrderByOrderId并传递请求对象时,客户端正在设置OrderCriteria类型的条件&如果您查看我上面提到的OperationContext RequestMessage,我可以看到参数已设置,但不知何故WCF无法反序列化OrderRequest对象的criteria属性&因此如果是来自Java客户端的POST方法,则变为NULL;如果使用嗅探器工具检查详细信息,则不是.Net客户端的GET方法。

您确定.Net请求来自GET吗?GET请求不能有正文,所以你真的不能有你发布的示例。不,事实并非如此。当客户端调用GetOrderByOrderId并传递请求对象时,客户端正在设置OrderCriteria类型的条件&如果您查看我上面提到的OperationContext RequestMessage,我可以看到参数已设置,但不知何故WCF无法反序列化OrderRequest对象的criteria属性&因此如果是来自Java客户端的POST方法,则变为NULL,而不是.Net客户端,如果使用嗅探器工具检查详细信息,则该客户端是GET方法。