Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WCF中支持具有属性的XSD_C#_Wcf_Xsd_Wsdl - Fatal编程技术网

C# 在WCF中支持具有属性的XSD

C# 在WCF中支持具有属性的XSD,c#,wcf,xsd,wsdl,C#,Wcf,Xsd,Wsdl,我们的项目中有一些XSD,它们定义使用属性和元素来指定属性值的类型,例如: <Instrument name="blah"> </Instrument> (GetInstrumentRequest和GetInstrumentResponse应仅展开为参数和返回值) 原因是数据协定序列化程序不支持具有属性的复杂类型,但我确实在某个地方读到过,如果使用document/literal而不是document/literal包装来定义WSDL,schemagen将退回到支持属性

我们的项目中有一些XSD,它们定义使用属性和元素来指定属性值的类型,例如:

<Instrument name="blah">
</Instrument>
(GetInstrumentRequest和GetInstrumentResponse应仅展开为参数和返回值)

原因是数据协定序列化程序不支持具有属性的复杂类型,但我确实在某个地方读到过,如果使用document/literal而不是document/literal包装来定义WSDL,schemagen将退回到支持属性的XmlSerializer实现。到目前为止,我试图让它工作失败: //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>


很抱歉回答了我自己的问题。在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>


在前面的示例中从未使用过nillable属性。抱歉,一定是转储了错误的wsdl。根据经验,我发现nillable=true会导致.net wsdl生成出现问题(例如,在上述情况下,当nillable=true存在时,或者当nillable=true未应用于字符串参数/返回类型时)。其他问题似乎是命名约定,它比类似的java端wsdl->代码生成框架(如axis或cxf)更严格。
<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>