svcutil.exe未为minOccurs=0生成指定字段



使用svcutil.exe从本地文件系统的文件上的wsdl+xsd生成代码。以前使用wsdl.exe。当字段是可选的(即minOccurs="0")时,如果类型是值类型(如int或enum),则wsdl.exe用于生成指定的布尔值。

根据文档,当使用XmlSerializer调用svcutil时,它也应该这样做,但在我的情况下,它没有这样做。这样称呼它:

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

您尝试过wscfblue吗?我发现它很有用。

http://wscfblue.codeplex.com/

最新更新