svcutil.exeを使用して、ローカルファイルシステムのファイルでwsdlとxsdからコードを生成します。以前に使用されたwsdl.exe。フィールドがオプションの場合(つまり、minOccurs = "0"の場合)、タイプが値タイプ(intやenumなど)の場合、wsdl.exeを使用して指定されたブール値を生成します。
ドキュメントによると、svcutilはXmlSerializerで呼び出されたときにもこれを行う必要がありますが、私の場合はそうではありません。このように呼び出す:
svcutil WebServiceA.wsdl * .xsd / noConfig / serializer:XmlSerializer
指定フィールドが生成されないのはなぜですか?wsdlのフィールドにnillableを追加したくないのは、それは何か別のことを意味し、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;
}
}