我们的项目中有一些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应该打包到参数并仅返回值。)
原因是数据契约序列化程序不支持带属性的复杂类型,但我确实读过某个地方,如果你使用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>
答案 0 :(得分:4)
<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>