简体   繁体   English

从服务参考生成C#服务框架

[英]Generate c# service skeleton from service reference

I created a service reference with VS to a soap service. 我使用VS创建了一个对肥皂服务的服务引用。 Now the server is offline and I would like to build a simple server for testing purposes. 现在服务器已脱机,我想构建一个简单的服务器进行测试。 I've already tried wsdl.exe with the wsdl file but didn't work because it couldn't reach the server. 我已经用wsdl文件尝试过wsdl.exe,但由于无法到达服务器而无法正常工作。

Is there any simple way to acheive this? 有没有简单的方法可以做到这一点? Of course, I'm not expecting any business logic to be magically created, just the structures and empty methods. 当然,我不希望会神奇地创建任何业务逻辑,而只是结构和空方法。 Then I'll make it respond with dummy data. 然后,我将使其以伪数据进行响应。

In the folder [project]\\ServiceReferences\\[service reference name] you'll find two files: one .wsdl and other .xsd 在文件夹[project] \\ ServiceReferences \\ [service reference name]中,您将找到两个文件:一个.wsdl和另一个.xsd

The xsd file contains the information that wsdl.exe was trying to get online. xsd文件包含wsdl.exe试图联机的信息。 So running: 运行:

wsdl /language:CS /serverInterface file.wsdl file.xsd

will create the interface for the service. 将为服务创建接口。 Then, create a new Wsdl Service Library project, add the interface (the new .cs file found in the same folder than wsdl.exe) and add the correct attributes to the interface, methods and data objects (if there's any). 然后,创建一个新的Wsdl Service Library项目,添加接口(在与wsdl.exe相同的文件夹中找到的新.cs文件),并将正确的属性添加到接口,方法和数据对象(如果有)。

Creating the service class is easy now that you have the interface. 现在,有了接口,创建服务类很容易。

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

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