简体   繁体   English

如何从WSDL.exe生成客户端和接口代码?

[英]How do I generate both client and interface code from WSDL.exe?

I'm writing some .NET 2.0 ASMX services. 我正在编写一些.NET 2.0 ASMX服务。 I have a scenario where I need to generate a web service proxy with WSDL.exe, but the generated class doesn't implement an interface, so I can't fake out the web service for testing. 我有一个场景,我需要使用WSDL.exe生成一个Web服务代理,但生成的类没有实现一个接口,所以我不能伪造Web服务进行测试。

Here's one approach I'm trying, but it doesn't compile at the moment: I'm aware that WSDL.exe can generate interfaces using the /serverInterface option. 这是我正在尝试的一种方法,但目前还没有编译:我知道WSDL.exe可以使用/serverInterface选项生成接口。 In principle, I'd like to generate both Interface and Proxy classes as follows: 原则上,我想生成接口和代理类,如下所示:

wsdl MyWebService.wsdl /nologo /l:CS /namespace:Juliet.Services /o:C:\\projects\\JulietService\\MyWebServiceInterface.cs /serverInterface wsdl MyWebService.wsdl / nologo / l:CS /namespace:Juliet.Services /o:C:\\projects\\JulietService\\MyWebServiceInterface.cs / serverInterface

wsdl MyWebService.wsdl /nologo /l:CS /namespace:Juliet.Services /o:C:\\projects\\JulietService\\MyWebServiceProxy.cs wsdl MyWebService.wsdl / nologo / l:CS /namespace:Juliet.Services /o:C:\\projects\\JulietService\\MyWebServiceProxy.cs

Then include both files in my project. 然后在我的项目中包含这两个文件。 Afterward I should be able to derive my own class from the generated Proxy and implement the generated interface as follows: 之后我应该能够从生成的Proxy派生自己的类,并按如下方式实现生成的接口:

public class MockableWebService : MyWebService, IMyWebServiceSoap11Binding
{
    // No implementation, the interface is already implicitly implemented
    // from the methods in the base class.
}

This should work in principle, except both interface and proxy files will auto-generate the same class definitions for my Request/Response messages, resulting in hundreds of errors of the type The namespace 'Juliet.Services' already contains a definition for 'ABC' . 这应该原则上工作, 除了接口和代理文件将自动生成我的请求/响应消息的相同类定义,导致数百个类型的错误The namespace 'Juliet.Services' already contains a definition for 'ABC'


I'd like to keep the interface/proxy generation as automated as possible -- meaning, I want to avoid modifying generated code by hand at all costs. 我想保持接口/代理生成尽可能自动化 - 这意味着,我想避免不惜一切代价手动修改生成的代码。

Can anyone suggest a way to generate the interface and proxy at the same time with WSDL.exe, or a better way to get the results described above? 任何人都可以建议使用WSDL.exe同时生成接口和代理的方法,或者更好的方法来获得上述结果?

Doesn't the .NET 2.0 WSDL.EXE generate partial classes? .NET 2.0 WSDL.EXE不生成部分类吗? Then you can implement the interface on another class part: 然后你可以在另一个类部分实现接口:

public partial class MockableWebService : IMyWebServiceSoap11Binding
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM