2011-07-11 104 views
2

我在客戶端C#Web應用程序中使用軸(JAVA)Web服務時遇到問題。我必須使用適合JAVA客戶端的第三方Web服務!當我們使用SoapUI進行測試時,它可以很好地工作。 我已經添加了Web服務和服務引用(asmx和wcf),但兩個引用的作用相同!我認爲我們在使用wsdl.exe(reference.cs)生成的代碼時遇到問題 因爲它無法反序列化從服務器支持的響應。 我可以在調試模式下看到SOAP Response,並且我知道響應是正確的。但是,我們有例外「XML文檔格式不正確!」,「根命名空間缺失」時,反序列化進程開始從.Net中消費AXIS webservice問題

響應:

<?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> 
    <processRequestResponse xmlns="http://www.mytown.com"> 
     <ETIResponse xmlns=""> 
     <ns1:TransactionID xmlns:ns1="http://www.mytown.com">CDK11341818404883</ns1:TransactionID> 
     <ns2:OrigResponseMessage xmlns:ns2="http://www.mytown.com">.....</ns2:OrigResponseMessage> 
     <ns3:CommandStatus xmlns:ns3="http://www.mytown.com">INVALID</ns3:CommandStatus> 
     <ns4:ResultCode xmlns:ns4="http://www.mytown.com">21</ns4:ResultCode> 
     </ETIResponse> 
    </processRequestResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

WSDL:

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions targetNamespace="http://www.mytown.com" 
        xmlns:apachesoap="http://xml.apache.org/xml-soap" 
        xmlns:impl="http://www.mytown.com" 
        xmlns:intf="http://www.mytown.com" 
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <wsdl:types> 
    <schema targetNamespace="http://www.mytown.com" xmlns="http://www.w3.org/2001/XMLSchema"> 
     <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> 
     <complexType name="ETIParameter"> 
     <sequence> 
      <element name="key" nillable="true" type="xsd:string"/> 
      <element name="value" nillable="true" type="xsd:string"/> 
     </sequence> 
     </complexType> 
     <complexType name="ETIParameters"> 
     <sequence> 
      <element maxOccurs="unbounded" minOccurs="0" name="Parameter" nillable="true" type="impl:ETIParameter"/> 
     </sequence> 
     </complexType> 
     <complexType name="ETIRequestType"> 
     <sequence> 
      <element name="RequestMessage" nillable="true" type="xsd:string"/> 
      <element name="ClientID" nillable="true" type="xsd:string"/> 
      <element name="Password" nillable="true" type="xsd:string"/> 
      <element maxOccurs="1" minOccurs="0" name="Parameters" nillable="true" type="impl:ETIParameters"/> 
     </sequence> 
     </complexType> 
     <simpleType name="CommandStatusType"> 
     <restriction base="xsd:string"> 
      <enumeration value="OK"/> 
      <enumeration value="SYSTEM-ERROR"/> 
      <enumeration value="SYNTAX-ERROR"/> 
      <enumeration value="INVALID"/> 
      <enumeration value="ERROR"/> 
     </restriction> 
     </simpleType> 
     <complexType name="ETIResponseType"> 
     <sequence> 
      <element maxOccurs="1" minOccurs="0" name="TransactionID" nillable="true" type="xsd:string"/> 
      <element name="OrigResponseMessage" nillable="true" type="xsd:string"/> 
      <element maxOccurs="1" minOccurs="0" name="TermResponseMessage" nillable="true" type="xsd:string"/> 
      <element name="CommandStatus" nillable="true" type="impl:CommandStatusType"/> 
      <element name="ResultCode" type="xsd:int"/> 
      <element maxOccurs="1" minOccurs="0" name="ErrorMsg" nillable="true" type="xsd:string"/> 
     </sequence> 
     </complexType> 
    </schema> 
    </wsdl:types> 
    <wsdl:message name="processRequestRequest"> 
    <wsdl:part name="ETIRequest" type="impl:ETIRequestType"/> 
    </wsdl:message> 
    <wsdl:message name="processRequestResponse"> 
    <wsdl:part name="ETIResponse" type="impl:ETIResponseType"/> 
    </wsdl:message> 
    <wsdl:portType name="ETI_Type"> 
    <wsdl:operation name="processRequest" parameterOrder="ETIRequest"> 
     <wsdl:input message="impl:processRequestRequest" name="processRequestRequest"/> 
     <wsdl:output message="impl:processRequestResponse" name="processRequestResponse"/> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="ETICoreSoapBinding" type="impl:ETI_Type"> 
    <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="processRequest"> 
     <wsdlsoap:operation soapAction="capeconnect:ETI_WebService:ETI_Type#processRequest"/> 
     <wsdl:input name="processRequestRequest"> 
     <wsdlsoap:body namespace="http://www.mytown.com" use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="processRequestResponse"> 
     <wsdlsoap:body namespace="http://www.mytown.com" use="literal"/> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="ETI_WebService"> 
    <wsdl:port binding="impl:ETICoreSoapBinding" name="ETICore"> 
     <wsdlsoap:address location="https://X.X.X.X/banks/services/ETICore"/> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

迴應部分來自參考。cs

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")] 
    [System.SerializableAttribute()] 
    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.ComponentModel.DesignerCategoryAttribute("code")] 
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.mytown.com")] 
    public partial class ETIResponseType 
    { 

     private string transactionIDField; 

     private string origResponseMessageField; 

     private string termResponseMessageField; 

     private string commandStatusField; 

     private int resultCodeField; 

     private string errorMsgField; 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] 
     public string TransactionID 
     { 
      get 
      { 
       return this.transactionIDField; 
      } 
      set 
      { 
       this.transactionIDField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] 
     public string OrigResponseMessage 
     { 
      get 
      { 
       return this.origResponseMessageField; 
      } 
      set 
      { 
       this.origResponseMessageField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] 
     public string TermResponseMessage 
     { 
      get 
      { 
       return this.termResponseMessageField; 
      } 
      set 
      { 
       this.termResponseMessageField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] 
     public string CommandStatus 
     { 
      get 
      { 
       return this.commandStatusField; 
      } 
      set 
      { 
       this.commandStatusField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
     public int ResultCode 
     { 
      get 
      { 
       return this.resultCodeField; 
      } 
      set 
      { 
       this.resultCodeField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] 
     public string ErrorMsg 
     { 
      get 
      { 
       return this.errorMsgField; 
      } 
      set 
      { 
       this.errorMsgField = value; 
      } 
     } 
} 

我知道我們有一個命名空間和命名空間前綴和生成的代碼 問題,如果我們增加WCF參考我們獲得清晰異常消息:

There was an error in serializing body of message : 'There was an error generating the XML document.'. Please see InnerException for more details. 
The prefix '' is bound to the namespace '' and cannot be changed to 'http://www.mytown.com'. 

任何意見或幫助?

感謝

回答

1

在我看來,響應根據XSD/WSDL無效。這就是問題所在:

<ETIResponse xmlns="">...</ETIResponse> 

此元素聲明沒有命名空間的默認前綴,但是:

您需要擺脫那xmlns=""或使用xmlns="http://www.mytown.com"。嘗試使用Fiddler來攔截響應並對其進行更改,以便檢查它是否真的有效。

如果確實如此,無論是問這些Java開發人員,因此返回有效響應修改其服務或WCF的情況下實現ASMX或IClientMessageInspector的情況下定製SoapExtension並重新格式化消息。

+0

嗨。感謝您的回覆。 我已經實現Custome Sope擴展befor張貼我的問題堆棧溢出。 存在相同的錯誤。 在這兩種情況下,我都有同樣的錯誤!經過大量的工作後,我們纔有了 – Navid

+0

!最終問題解決了。我測試了兩個SoapExtention for asmx和IClientMessageInspector。我傾向於將「Form = System.Xml.Schema.XmlSchemaForm.Unqualified」更改爲「合格」以用於ETIResponse成員.. – Navid