从 .Net 使用 AXIS Web 服务问题

发布于 2024-11-19 13:01:10 字数 9242 浏览 3 评论 0原文

我在客户端 C# Web 应用程序中使用 axis (JAVA) Web 服务时遇到问题。我必须使用与 JAVA 客户端正常工作的第三方 Web 服务!当我们用 SoapUI 测试它时,它工作得很好。 我添加了 Web 服务和服务参考(asmx 和 wcf),但两个参考的工作原理相同!我认为我们对 wsdl.exe 生成的代码有问题(reference.cs) 因为它无法反序列化服务器返回的响应。 我可以在调试模式下看到 SOAP 响应,并且我知道响应是正确的。但是当反序列化过程启动时,我们遇到异常“XML 文档格式不正确!”、“根命名空间丢失”

Response:

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

有任何评论或帮助吗?

谢谢

I have problem with consuming axis (JAVA) web service inside a client C# web application. I have to use third Party web service that works properly with JAVA clients! When we test it with SoapUI it works perfectly.
I have added web service and service reference ( asmx and wcf) but both references works same ! I think we have problem with code generated by wsdl.exe (reference.cs)
Because it cannot deserialize the response backed from server.
I can see SOAP Response in debug mode and I know the response is correct. But we have exception “XML Document Not Well Formed!”, “Root Namespace Is Missing” when Deserialization Process start

Response:

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

Response Section From 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;
            }
       }
}

I know we have problem with namespaces and namespace prefix and generated Code
if we add WCF Reference we get clear Exception Message:

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'.

Any Comments or Help?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角迷惘 2024-11-26 13:01:10

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

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

该元素没有声明默认前缀的命名空间,但是:

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

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

In my opinion the response is not valid according to XSD / WSDL. This is the problem:

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

This element declares no namespace for default prefix but:

You need to get rid of that xmlns="" or use xmlns="http://www.mytown.com". Try to use Fiddler to intercept the response and change it so you can check that it really works.

If it does, either ask those Java developers to modify their service so it returns valid response or implement custom SoapExtension in case of ASMX or IClientMessageInspector in case of WCF and reformat the message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文