问题
I am working on a project that uses the contract first approach. I was given a WSDL
and three xsd's
. When I use svcutil
it generates a wrapper around the response class like so:
public partial class getDataByIdResponse1 {
public getDataByIdResponse getDataByIdResponse;
public getDataByIdResponse1() {
}
public getDataByIdResponse1(getDataByIdResponse getDataByIdResponse) {
this.getDataByIdResponse = getDataByIdResponse;
}
}
The getDataByIdResponse
is wrapped inside a getDataByIdResponse1
object. This is done by svcutil
and I have no idea why. The getDataByIdResponse1
object does not exist in the WSDL
:
<wsdl:message name="getDataById">
<wsdl:part name="response" element="tns:getDataByIdResponse"/>
</wsdl:message>
<xs:element name="getDataByIdResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="data" type="sbc:DataType" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
Why is the type getDataByIdResponse
wrapped in getDataByIdResponse1
? Is there a switch for svcutil
I should have used?
回答1:
I am in the same situation (contract-first) and svcutil is generating this same kind of code for me but I just closed my eyes took a deep breath and accepted it :-)
Just use the types without the numeric postfix and it just works.
回答2:
I'm in the same boat as you but I don't just want to live with it. I want to generate clean (unwrapped) contracts. If the wsdl and xsd's were given to you then there are some rules that your schema and wsdl need to follow in order for svc util to generate unwrapped code. These links helped me understand the issue a little better
http://pzf.fremantle.org/2007/05/handlign.html
http://mharbauer.wordpress.com/2007/10/19/wcf-datacontract-serializer-and-documentwrapped/
For now my schema and wsdl are small enough that I can tweak them to adhere to this rules.
However, like Ron, I've also been in situations where the easiest thing is just to live with it.
Hope this helps.
来源:https://stackoverflow.com/questions/6264226/svcutil-generated-unneccesary-wrapper-classes