调用Java Web Service时,C#响应对象包含null

时间:2009-12-21 23:00:12

标签: c# java service response

我已经发送了以下wsdl。我使用wsdl.exe生成了C#代理,并创建了我的c#网页。使用Fiddler我查看了SOAP响应,它包含数据。为了使C#程序接受SOAP响应,需要进行哪些修改的指导。请原谅wsdl的格式我不确定哪种格式可以获得最佳效果。

WSDL

<?xml version="1.0" encoding="UTF-8" ?>
   <wsdl:definitions xmlns:tns="https://wwf.web.spiritaero.com/tot/moves" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CreateMoveHistory" targetNamespace="https://wwf.web.spiritaero.com/tot/moves" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
   <wsdl:types>
     <xsd:schema targetNamespace="https://wwf.web.spiritaero.com/tot/moves" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="CreateMoveHistoryResponse" type="tns:ReturnMessage" />
      <xsd:element name="CreateMoveHistoryRequest" type="tns:CreateMoveHistoryContract" />
       <xsd:complexType name="CreateMoveHistoryContract">
         <xsd:sequence minOccurs="1" maxOccurs="1">
          <xsd:element name="FromApplication" type="xsd:string" />
          <xsd:element name="ActionName" type="xsd:string" />
          <xsd:element name="OrderNumber" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="WorkCenter" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Zone" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Building" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Floor" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Post" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="SubCode" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="SubId" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="ScanDate" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="AntennaId" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="AntennaDescription" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="PartNumber" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
      </xsd:complexType>
       <xsd:complexType name="CreateMoveHistoryFacade">
         <xsd:sequence minOccurs="1" maxOccurs="1">
          <xsd:element name="FromApplication" type="xsd:string" />
          <xsd:element name="ActionName" type="xsd:string" />
          <xsd:element name="OrderNumber" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="WorkCenter" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Zone" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Building" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Floor" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="Post" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="SubCode" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="SubId" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="ScanDate" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="AntennaId" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="AntennaDescription" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="PartNumber" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="ReturnCode" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
          <xsd:element name="ReturnMessage" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
      </xsd:complexType>
       <xsd:complexType name="ReturnMessage">
         <xsd:sequence minOccurs="1" maxOccurs="1">
          <xsd:element name="Message" nillable="false" type="xsd:string" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
   <wsdl:message name="createMoveHistoryResponse">
    <wsdl:part element="tns:CreateMoveHistoryResponse" name="createMoveHistoryResponse" />
  </wsdl:message>
   <wsdl:message name="createMoveHistoryRequest">
    <wsdl:part element="tns:CreateMoveHistoryRequest" name="createMoveHistoryRequest" />
  </wsdl:message>
   <wsdl:portType name="CreateMoveHistoryPort">
     <wsdl:operation name="createMoveHistory">
      <wsdl:input message="tns:createMoveHistoryRequest" />
      <wsdl:output message="tns:createMoveHistoryResponse" />
    </wsdl:operation>
  </wsdl:portType>
   <wsdl:binding name="CreateMoveHistorySoap" type="tns:CreateMoveHistoryPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
     <wsdl:operation name="createMoveHistory">
      <soap:operation soapAction="https://wwf.web.spiritaero.com/tot/moves/CreateMoveHistory" />
       <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
       <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
   <wsdl:service name="CreateMoveHistory">
     <wsdl:port binding="tns:CreateMoveHistorySoap" name="CreateMoveHistory">
      <soap:address location="http://pc790503.corp.spiritaero.com:8080/tot/moves?action=CreateMoveHistory" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

的Fiddler

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
<soapenv:Header/>   
 <soapenv:Body> 
  <ReturnMessage xmlns="https://wwf.web.spiritaero.com/tot/moves">           
   <Message>Successful</Message>      
  </ReturnMessage>   
 </soapenv:Body> 
</soapenv:Envelope>

为响应生成的C#代码

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="https://wwf.web.spiritaero.com/tot/moves")]
    public partial class CreateMoveHistoryResponse {

    private string messageField;

    /// <remarks/>
    public string Message {
        get {
            return this.messageField;
        }
        set {
            this.messageField = value;
        }
    }
}

调用Web服务的C#代码

CreateMoveHistory proxy;
        CreateMoveHistoryRequest cmhRequest;
        CreateMoveHistoryResponse msg;
....

            msg = new CreateMoveHistoryResponse();
            proxy = new CreateMoveHistory();
            cmhRequest = new CreateMoveHistoryRequest();
            cmhRequest.OrderNumber = "12345";
            cmhRequest.Zone = "2";
            cmhRequest.Building = "297F";
            cmhRequest.Floor = "1";
            cmhRequest.Post = "XX";
            msg = proxy.createMoveHistory(cmhRequest);

此致

d。富勒

3 个答案:

答案 0 :(得分:1)

如果您使用WebReferences,请检查wsdl文件以确保targetNamespace和名称空间相同。

希望这有帮助!

答案 1 :(得分:0)

首先,我会监控您的网络流量(HTTP)以确保返回某些内容。如果是这种情况,我记得在将Web服务从C#调用到Java时反对名称空间有问题,反之亦然。其中一方有名称空间声明,另一方没有,其中一方认为它没有数据,因为它正在寻找其他东西。

这是一个非常通用的解释,但那是很久以前的事了。我记得这是问题的正面原因。您可能必须使用不同的WS客户端来监视有效的呼叫,然后在从C#客户端执行呼叫时检查有什么不同。

答案 2 :(得分:0)

我在肥皂回复中没有看到CreateMoveHistoryResponse定义...相反,我看到了ReturnMessage ...我相信存在问题。

我在wsdl定义中看到<xsd:element name="CreateMoveHistoryResponse" type="tns:ReturnMessage" />,但我不知道为什么wsdl.exe util不会生成正确类型的类。

希望这有助于解决问题...

相关问题