tags:

views:

1205

answers:

1

Hi,

We have some XSDs in our project that define types that use attributes, as well as elements, to specify property values, e.g.:

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

I use these XSDs to define a schema used by a WSDL, but when I run it through schemagen, the generated code is unwrapped. For example:

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);
 }

(the GetInstrumentRequest and GetInstrumentResponse should be unwrapped to the parameters and return value only).

The reason for this is that the data contract serializer doesn't support complex types with attributes, but I did read somewhere that if you use document/literal, rather than document/literal wrapped to define the WSDL, schemagen will fall back to an XmlSerializer implementation, that does support attributes. So far, my attempts to get this to work have failed: // CODEGEN: Generating message contract since the operation GetInstrument is neither RPC nor document wrapped.

So, is this assumption about document/literal faulty? Is there any way to generate unwrapped interface code from a WSDL that defines complex types with attributes?

Here's the modified document/literal WSDL I am using:

<?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"&gt;
    <wsdl:types>
        <xs:schema targetNamespace="http://tempuri.org/"&gt;
            <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"/&gt;
        <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  A: 

apologies for answering my own question. It seems that just removing the nillable="true" statement from the operation response type, in th document/literal/wrapped WSDL types schema does the trick - no need to drop to document/literal.

<wsdl:types>
    <xs:schema elementFormDefault="qualified" targetNamespace="http://com.barcap.cbts.core.messaging.rpc/"&gt;
        <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>
Andy