简体   繁体   English

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

[英]C# response object contains null when calling Java Web Service

I've been sent the following wsdl. 我已收到以下wsdl。 I generated the C# proxy using wsdl.exe and also created my c# web page. 我使用wsdl.exe生成了C#代理,还创建了c#网页。 Using Fiddler I have looked at the SOAP response and it contains data. 使用Fiddler,我查看了SOAP响应,它包含数据。 Any guidance on what modification is needed in order to get the C# program to accept the SOAP response. 为了使C#程序接受SOAP响应,需要进行任何修改的指导。 Please excuse the formatting of the wsdl I was uncertain as to which format to use for best results. 请原谅wsdl的格式,我不确定该使用哪种格式以获得最佳效果。

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# Code Generated for response 生成用于响应的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;
        }
    }
}

C# code calling web service C#代码调用Web服务

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);

Regards, 问候,

D. Fuller D.富勒

If you use WebReferences, let check wsdl file to be sure targetNamespace and name space are same. 如果使用WebReferences,请检查wsdl文件以确保targetNamespace和名称空间相同。

Hope this help! 希望有帮助!

Well, first of all, I would monitor your network traffic (HTTP) to ensure that something is being returned. 好吧,首先,我将监视您的网络流量(HTTP),以确保返回了某些内容。 If that is the case, I remember having problems with namespaces when calling Web Service from C# to Java and vice-versa. 如果是这种情况,我记得从C#到Java调用Web Service时,名称空间存在问题,反之亦然。 One of the sides had the namespace declaration, the other didn't, and one of the sides would think that it got no data because it was looking for something else. 一方有名称空间声明,另一方则没有,而一方则认为它没有数据,因为它在寻找其他内容。

This is a very generic explanation, but that was a long time ago. 这是一个非常笼统的解释,但这是很久以前的事了。 I remember that it was positively a cause of issues. 我记得这肯定是引起问题的原因。 You may have to use a different WS client to monitor a valid call, and then check what's different when you perform the call from the C# client. 您可能必须使用其他WS客户端来监视有效的调用,然后检查从C#客户端执行调用时的区别。

I don't see a CreateMoveHistoryResponse definition in your soap response... Instead I see a ReturnMessage ... and I believe there is the problem. 我在您的肥皂响应中没有看到CreateMoveHistoryResponse定义...而是看到了ReturnMessage ...,并且我相信是有问题的。

I see the <xsd:element name="CreateMoveHistoryResponse" type="tns:ReturnMessage" /> in your wsdl definition but I don't know why the wsdl.exe util don't generate the class of the correct type. 我在您的wsdl定义中看到了<xsd:element name="CreateMoveHistoryResponse" type="tns:ReturnMessage" /> ,但我不知道wsdl.exe util为什么不生成正确类型的类。

Hope this helps solving the issue... 希望这有助于解决问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM