Поддержка XSD с атрибутами в WCF

В нашем проекте есть несколько XSD, которые определяют типы, использующие атрибуты, а также элементы для указания значений свойств, например:

<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 должны быть развернуты только до параметров и возвращаемого значения).

Причина этого в том, что сериализатор контракта данных не поддерживает сложные типы с атрибутами, но я где-то читал, что если вы используете документ/литерал, а не документ/литерал, обернутый для определения 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>

person Andy    schedule 26.02.2009    source источник


Ответы (1)


извините за ответ на мой собственный вопрос. Кажется, что простое удаление оператора nillable="true" из типа ответа операции в схеме типов document/literal/wrapped WSDL делает свое дело - нет необходимости переходить к 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>
person Andy    schedule 26.02.2009
comment
атрибут nillable никогда не использовался в вашем предыдущем примере. - person D3vtr0n; 28.01.2012
comment
Извиняюсь, должно быть, сбросил не тот файл wsdl. Как правило, я обнаружил, что nillable=true вызывает проблемы с генерацией .net wsdl (например, в приведенном выше случае, когда он присутствует или когда nillable=true не применяется к типам строковых параметров/возвратов). Другие проблемы, по-видимому, связаны с соглашениями об именах, которые являются более строгими, чем эквивалентные среды генерации кода wsdl-› на стороне Java, такие как axis или cxf. - person Andy; 31.01.2012