1

我在我的 c# 应用程序中使用的 Java Web 服务之一有一个返回类型“marketCalendar”,其定义如下 wsdl. WSDL 的 Target 名称空间是http://www.xyz.com

<?xml version="1.0"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.xyz.com/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.xyz.com/api" name="cscreen" targetNamespace="http://www.xyz.com/wsdl">
<wsdl:types>
    <xsd:schema targetNamespace="http://www.xyz.com/api" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="getMarketCalendar">
            <xsd:complexType>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="marketCalendar">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="country" minOccurs="1" maxOccurs="unbounded">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="exchange" minOccurs="1" maxOccurs="unbounded">
                                    <xsd:complexType>
                                        <xsd:sequence>
                                            <xsd:element name="calendarDay" minOccurs="1" maxOccurs="unbounded">
                                                <xsd:complexType>
                                                    <xsd:attribute name="type" type="calendarDayType" use="required"/>
                                                    <xsd:attribute name="date" type="xsd:string" use="required"/>
                                                </xsd:complexType>
                                            </xsd:element>
                                        </xsd:sequence>
                                        <xsd:attribute name="name" type="xsd:string" use="required"/>
                                    </xsd:complexType>
                                </xsd:element>
                            </xsd:sequence>
                            <xsd:attribute name="name" type="xsd:string" use="required"/>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            <xsd:attribute name="sessionID" type="xsd:string" use="required"/>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>
</wsdl:types>   
<!--Get information on calendars -->
<wsdl:message name="getMarketCalendarRsp">
    <wsdl:part name="marketCalendar" element="marketCalendar"/>
</wsdl:message>
<wsdl:message name="getMarketCalendarReq">
    <wsdl:part name="getMarketCalendar" element="getMarketCalendar"/>
</wsdl:message>
<wsdl:portType name="Cscreen_PortType">
    <wsdl:operation name="getMarketCalendarRequest">
        <wsdl:input message="tns:getMarketCalendarReq"/>
        <wsdl:output message="tns:getMarketCalendarRsp"/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Cscreen_Binding" type="tns:Cscreen_PortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>       
    <wsdl:operation name="getMarketCalendarRequest">
        <soap:operation soapAction=""/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="Cscreen_Service">
    <wsdl:documentation>This WSDL file describes how to access the Cscreen OTC Equity Derivatives Price Discovery Platform through the SOAP API. This software was developed by Cinnober Financial Technology.</wsdl:documentation>
    <wsdl:port name="Cscreen_Port" binding="tns:Cscreen_Binding">
        <soap:address location="https://hostname/api/v16"/>
        <!-- hostname can for example be stage.xyz.com and www.xyz.com -->
    </wsdl:port>
</wsdl:service>

并且相应的 C# 代理有以下解释,

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.xyz.com")]
public partial class marketCalendar {

    private marketCalendarCountry[] countryField;

    private string sessionIDField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("country", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public marketCalendarCountry[] country {
        get {
            return this.countryField;
        }
        set {
            this.countryField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string sessionID {
        get {
            return this.sessionIDField;
        }
        set {
            this.sessionIDField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.xyz.com")]
public partial class marketCalendarCountry {

    private marketCalendarCountryExchange[] exchangeField;

    private string nameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("exchange", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public marketCalendarCountryExchange[] exchange {
        get {
            return this.exchangeField;
        }
        set {
            this.exchangeField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.xyz.com")]
public partial class marketCalendarCountryExchange {

    private marketCalendarCountryExchangeCalendarDay[] calendarDayField;

    private string nameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("calendarDay", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public marketCalendarCountryExchangeCalendarDay[] calendarDay {
        get {
            return this.calendarDayField;
        }
        set {
            this.calendarDayField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.xyz.com")]
public partial class marketCalendarCountryExchangeCalendarDay {

    private calendarDayType typeField;

    private string dateField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public calendarDayType type {
        get {
            return this.typeField;
        }
        set {
            this.typeField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string date {
        get {
            return this.dateField;
        }
        set {
            this.dateField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.xyz.com")]
public enum calendarDayType {

    /// <remarks/>
    HOLIDAY,

    /// <remarks/>
    EXPIRATION,
}

问题# 我的 c# 应用程序调用 java webservice 上的 GetMarketCalendar 方法,确实看到了 XML 响应,但无法将其反序列化回 marketCalendar 响应。所以我开始使用XGen 生成的类进行挖掘。

我注意到对于countryexchangecalendarDay类型- c# 的默认反序列化器将肥皂响应中的命名空间与空字符串进行比较,即

if (((object) Reader.LocalName == (object)id84_country && (object) Reader.NamespaceURI == (object)id2_Item)) {

其中传入的是 Reader.NamespaceURI = " http://www.xyz.com " 和 id2_Item = Reader.NameTable.Add(@""); 即空。由于比较失败,反序列化也失败。有什么解决办法吗?

这是 C# XMLSerializer 错误还是 wsdl 中的 marketCalendar 定义有问题?

4

0 回答 0