从.Net问题消费AXIS webservice

时间:2011-07-11 07:51:53

标签: .net wcf web-services asmx axis

我在客户端C#Web应用程序中使用axis(JAVA)Web服务时遇到问题。我必须使用与JAVA客户端正常工作的第三方Web服务!当我们用SoapUI进行测试时,它可以完美地工作。 我添加了Web服务和服务引用(asmx和wcf),但两个引用都相同!我认为wsdl.exe生成的代码存在问题(reference.cs) 因为它无法反序列化从服务器支持的响应。 我可以在调试模式下看到SOAP Response,我知道响应是正确的。但是,当反序列化过程开始时,我们有异常“XML文档形成不好!”,“根名称空间丢失”

响应:

<?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>

来自Reference.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 个答案:

答案 0 :(得分:1)

在我看来,根据XSD / WSDL,响应无效。这就是问题所在:

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

此元素声明默认前缀没有名称空间,但是:

您需要摆脱xmlns=""或使用xmlns="http://www.mytown.com"。尝试使用Fiddler拦截响应并进行更改,以便检查它是否真的有效。

如果是,请要求那些Java开发人员修改他们的服务,以便在ASMX的情况下返回有效的响应或实现自定义SoapExtension或在WCF的情况下实现IClientMessageInspector并重新格式化消息。