代码之家  ›  专栏  ›  技术社区  ›  Andy

在WCF中支持具有属性的XSD

  •  4
  • Andy  · 技术社区  · 17 年前

    <Instrument name="blah">
    </Instrument>
    

    我使用这些XSD来定义WSDL所使用的模式,但是当我通过schemagen运行它时,生成的代码被展开。例如:

    public interface InstrumentService
    {    
        // CODEGEN: Parameter 'GetInstrumentResponse' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
        GetInstrumentResponse GetInstrument(GetInstrumentRequest request);
     }
    

    (GetInstrumentRequest和GetInstrumentResponse应仅展开为参数和返回值)。

    //CODEGEN:正在生成消息协定,因为操作GetInstrument既不是RPC也不是文档包装的。

    那么,关于文档/文字的假设是否有缺陷?有没有办法从定义具有属性的复杂类型的WSDL生成未包装的接口代码?

    下面是我正在使用的经过修改的文档/文字WSDL:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions
        targetNamespace="http://tempuri.org/"
        xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
        xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
        xmlns:tns="http://tempuri.org/"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <wsdl:types>
            <xs:schema targetNamespace="http://tempuri.org/">
                <xs:complexType name="testComplexType">
                    <xs:sequence/>
                    <xs:attribute name="name" type="xs:string"/>
                </xs:complexType>
                <xs:element name="input" type="tns:testComplexType"/>
            </xs:schema>
        </wsdl:types>
        <wsdl:message name="GetInstrumentIn">
            <wsdl:part element="tns:input" name="input"/>
        </wsdl:message>
        <wsdl:message name="GetInstrumentOut"/>
        <wsdl:portType name="InstrumentService">
            <wsdl:operation name="GetInstrument">
                <wsdl:input message="tns:GetInstrumentIn"/>
                <wsdl:output message="tns:GetInstrumentOut"/>
            </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="InstrumentService" type="tns:InstrumentService">
            <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="GetInstrument">
                <soap:operation soapAction="GetInstrument" style="document"/>
                <wsdl:input>
                    <soap:body use="literal"/>
                </wsdl:input>
                <wsdl:output>
                    <soap:body use="literal"/>
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="InstrumentService">
            <wsdl:port binding="tns:InstrumentService" name="InstrumentService"/>
        </wsdl:service>
    </wsdl:definitions>
    
    1 回复  |  直到 17 年前
        1
  •  4
  •   Andy    17 年前

    很抱歉回答了我自己的问题。在document/literal/wrapped的WSDL类型模式中,似乎只要从操作响应类型中删除nillable=“true”语句就可以做到这一点——无需转到document/literal。

    <wsdl:types>
        <xs:schema elementFormDefault="qualified" targetNamespace="http://com.barcap.cbts.core.messaging.rpc/">
            <xs:element name="GetInstrument">
                <xs:complexType/>
            </xs:element>
            <xs:element name="GetInstrumentResponse">
                <xs:complexType>
                    <xs:sequence>
                        <!-- nillable="true" removed -->
                        <xs:element maxOccurs="1" minOccurs="0"
                            name="GetInstrumentResponse" type="tns:Instrument"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Instrument">
                <xs:sequence/>
                <xs:attribute name="name" type="xs:string"/> 
            </xs:complexType>
        </xs:schema>
    </wsdl:types>