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

时间:2011-07-06 22:57:52

标签: java .net wcf web-services

我有ws& 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}

请求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}

服务器的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>

2 个答案:

答案 0 :(得分:0)

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

[DataMember(EmitDefaultValue = false)]

还要查看此MSDN文章: - http://msdn.microsoft.com/en-us/library/aa347792.aspx

答案 1 :(得分:0)

不是不是这样。当我们客户端调用GetOrderByOrderId&amp;传递请求对象然后客户端正在设置OrderCriteria&amp;类型的条件。如果你看一下上面提到的OperationContext RequestMessage,我可以看到参数已经设置但是WCF不能反序列化OrderRequest对象的Criteria属性。因此,在Java客户端和POST客户端的POST方法中它变为NULL如果使用嗅探器工具查看详细信息,则不是.Net客户端是GET方法