svcutil 生成了不必要的包装类 [英] svcutil generated unneccesary wrapper classes

查看:22
本文介绍了svcutil 生成了不必要的包装类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个使用契约优先方法的项目.我得到了一个 WSDL 和三个 xsd's.当我使用 svcutil 时,它会围绕响应类生成一个包装器,如下所示:

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

getDataByIdResponse 被包裹在一个 getDataByIdResponse1 对象中.这是由 svcutil 完成的,我不知道为什么.getDataByIdResponse1 对象在 WSDL 中不存在:

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>

为什么 getDataByIdResponse 类型包含在 getDataByIdResponse1 中?有没有我应该使用的 svcutil 开关?

Why is the type getDataByIdResponse wrapped in getDataByIdResponse1? Is there a switch for svcutil I should have used?

推荐答案

我和你在同一条船上,但我不想忍受它.我想生成干净的(未包装的)合同.如果 wsdl 和 xsd 是给你的,那么你的架构和 wsdl 需要遵循一些规则,以便 svc util 生成解包代码.这些链接帮助我更好地理解了这个问题

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/

现在我的架构和 wsdl 足够小,我可以调整它们以遵守此规则.
然而,和 Ron 一样,我也遇到过最简单的事情就是忍受它.

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.

希望这会有所帮助.

这篇关于svcutil 生成了不必要的包装类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆