使用svcutil.exe从wsdl的+ xsd生成来自本地文件系统的文件的代码。以前用过wsdl.exe。当字段是可选的(即具有minOccurs =“0”)时,如果类型是值类型(如int或enum),wsdl.exe用于生成Specified布尔值。
根据文档,当使用XmlSerializer调用时,svcutil也应该这样做,但在我的情况下它不会。这样称呼它:
svcutil WebServiceA.wsdl * .xsd / noConfig / serializer:XmlSerializer
为什么未生成指定字段?我不想将nillable添加到wsdl中的字段,因为这意味着不同的东西,需要在Java后端进行更改。
要重现的示例代码: WebServiceA.wsdl:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://metric_web_service.uis.component.company.com/"
name="WebServiceA"
xmlns:tns="http://metric_web_service.uis.component.company.com/"
xmlns:ows="http://component_web_service.uis.component.company.com/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://metric_web_service.uis.component.company.com/" schemaLocation="WebServiceA.xsd"/>
</xsd:schema>
</types>
<message name="GetDataRequest">
<part name="parameters" element="tns:getDataRequest" />
</message>
<message name="GetDataResponse">
<part name="parameters" element="tns:getDataResponse" />
</message>
<portType name="WebServiceAPortType">
<operation name="getData">
<input message="tns:GetDataRequest" />
<output message="tns:GetDataResponse" />
</operation>
</portType>
<binding name="WebServiceABinding" type="tns:WebServiceAPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getData">
<soap:operation soapAction="getData" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="WebServiceA">
<port name="WebServiceAPort" binding="tns:WebServiceABinding">
<soap:address location="http://localhost:8080/web_services/WebServiceA?wsdl" />
</port>
</service>
</definitions>
WebServiceA.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://metric_web_service.uis.component.company.com/"
xmlns:ows="http://component_web_service.uis.component.company.com/"
targetNamespace="http://metric_web_service.uis.component.company.com/"
elementFormDefault="qualified" attributeFormDefault="qualified">
<!--<import namespace="http://component_web_service.uis.component.company.com/" schemaLocation="ComponentWebService.xsd"/>-->
<element name="getDataRequest" type="tns:GetDataRequestElement"/>
<element name="getDataResponse" type="tns:GetDataResponseElement"/>
<complexType name="GetDataRequestElement">
<sequence>
<element name="id" type="string" minOccurs="1" maxOccurs="1"/>
<element name="dataType" type="tns:DataType" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
<complexType name="GetDataResponseElement">
<sequence>
<element name="data" type="tns:DataCollection" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<complexType name="DataCollection">
<sequence>
<element name="data" type="tns:Data" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<complexType name="Data">
<sequence>
<element name="id" type="string" minOccurs="1" maxOccurs="1"/>
<element name="DataType" type="tns:DataType" minOccurs="1" maxOccurs="1"/>
<element name="value" type="double" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
<simpleType name="DataType">
<restriction base="string">
<enumeration value="TYPE_A"/>
<enumeration value="TYPE_B"/>
</restriction>
</simpleType>
</schema>
生成如下代码。请注意,getDataRequest类不包含任何可选(指定)字段,因此如果没有dataType,则无法执行“getData”调用。这是svcutil.exe中的另一个错误吗?
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="getDataRequest", WrapperNamespace="http://metric_web_service.uis.component.company.com/", IsWrapped=true)]
public partial class getDataRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://metric_web_service.uis.component.company.com/", Order=0)]
public string id;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://metric_web_service.uis.component.company.com/", Order=1)]
public DataType dataType;
public getDataRequest()
{
}
public getDataRequest(string id, DataType dataType)
{
this.id = id;
this.dataType = dataType;
}
}