首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从.Net问题中消费轴.Net服务

从.Net问题中消费轴.Net服务
EN

Stack Overflow用户
提问于 2011-07-11 07:51:52
回答 1查看 3K关注 0票数 2

我对客户端C# web应用程序中的消费轴(JAVA) web服务有问题。我必须使用第三方web服务,与JAVA客户端一起正常工作!当我们用SoapUI测试它时,它工作得很好。我已经添加了web服务和服务引用( asmx和wcf),但是这两个引用都是一样的!我认为wsdl.exe (reference.cs)生成的代码有问题,因为它不能反序列化服务器支持的响应。我可以在调试模式下看到SOAP响应,并且我知道响应是正确的。但是,在反序列化过程开始时,我们有异常“XML文档格式不好!”、“根名称空间缺失”。

响应:

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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

代码语言:javascript
复制
 [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引用,就会得到明确的异常消息:

代码语言:javascript
复制
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'.

有什么意见或帮助吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-11 09:16:09

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

代码语言:javascript
复制
<ETIResponse xmlns="">...</ETIResponse>

此元素不为默认前缀声明命名空间,但:

  • WSDL本身将目标命名空间声明为http://www.mytown.com,因此应该使用它。
  • http://www.mytown.com的父元素已经使用了默认命名空间。

您需要摆脱这个xmlns=""或使用xmlns="http://www.mytown.com"。尝试使用费德勒来拦截并更改响应,这样您就可以检查它是否真的工作了。

如果是这样的话,要么要求那些Java开发人员修改他们的服务以便返回有效的响应,要么在使用SoapExtensionIClientMessageInspector的情况下实现定制的WCF,并重新格式化消息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6647198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档