10

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

根据文档,当使用 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;
    }
}
4

1 回答 1

0

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

http://wscfblue.codeplex.com/

于 2014-12-04T03:37:33.163 回答