svcutil不为minOccurs = 0生成指定的字段 [英] svcutil NOT generating specified fields for minOccurs=0
问题描述
使用svcutil.exe从本地文件系统上的文件的wsdl + xsd生成代码.以前使用的wsdl.exe.当字段为可选字段时(即has minOccurs ="0"),wsdl.exe用于生成< fieldname>指定的布尔值(如果类型为 是一个值类型(例如int或enum).
Using svcutil.exe to generate code from wsdl's + xsd's on files from the local file system. Previously used wsdl.exe. When a field is optional (i.e. has minOccurs="0"), wsdl.exe used to generate a <fieldname>Specified boolean if the type is a value type (like int or enum).
根据文档,当用XmlSerializer调用svcutil时也应该这样做,但是在我的情况下不是.这样称呼:
According to documentation, svcutil should do this too when invoked with the XmlSerializer, but in my case it does not. Calling it like this:
svcutil WebServiceA.wsdl *.xsd /noConfig /serializer:XmlSerializer
为什么未生成指定"字段?我不想在wsdl中的字段中添加nillable,因为这意味着有所不同,并且需要在Java后端中进行更改.
Why are the Specified fields not generated? I do not want to add nillable to the fields in the wsdl, because that means something different and would require changes in the Java backend.
要复制的示例代码:
WebServiceA.wsdl:
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:
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类不包含任何可选的(Specified)字段,因此不可能执行"getData"操作.没有dataType的呼叫.这是svcutil.exe中的另一个错误吗?
Generates code like this. Note that the getDataRequest class does not contains any optional (Specified) fields, so it's impossible to do the "getData" call without a dataType. Is this another bug in 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;
}
}
推荐答案
有人吗?这是相当大的突破.连同我发布的其他问题,似乎svcutil是越野车的一种使用方式.我们正在考虑取消整个切换到WCF,并保持wsdl.exe:-(
Anybody? This is quite the dealbreaker. Along with the other issues I posted, it seems like svcutil is way to buggy to be used. We are thinking about cancelling the whole switchover to WCF and remain keeping wsdl.exe :-(
这篇关于svcutil不为minOccurs = 0生成指定的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!