В нашем проекте есть несколько 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>