在 Visual Studio 2010 中创建 WCF 服务引用时自定义消息协定
在 Visual Studio 2010 中添加 WCF 服务引用时是否可以修改消息契约的生成方式?具体来说,我希望请求和响应对象具有属性而不是公共字段。
我无法控制 WCF 服务本身,只能控制客户端。
Is it possible to modify how message contracts are generated when adding a WCF service reference in Visual Studio 2010? Specifically I want the request and response objects to have properties instead of public fields.
I have no control over the WCF service itself, just the client.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您无法控制生成的代理,但您可以在构建它们后对其进行修改。为什么要更改代理?
I don't think you can control the proxies that get generated, but you can modify them once they are built. Why do you want to change the proxy?
您无法控制生成的代理中的代码。如果需要,您可以使用 MetadataExchangeClient / ServiceContractGenerator 类自行生成代理。他们将为您提供一个 CodeDom 对象,其中包含您可以修改的代码(即将字段更改为属性)。 MSDN 论坛帖子中有一个使用 MEC/SCG 类的示例,网址为 http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/14100bbb-9a73-4bcc-b513-088bb2e5ec65。
You can't control the code in the generated proxy. If you want, you can do the proxy generation yourself, using the MetadataExchangeClient / ServiceContractGenerator classes. They'll give you a CodeDom object containing the code which you can modify (i.e., change fields into properties). There's an example of using the MEC/SCG classes in the MSDN forum post at http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/14100bbb-9a73-4bcc-b513-088bb2e5ec65.