如何从 wsdl 生成 Web 服务 [英] how to generate web service out of wsdl

查看:40
本文介绍了如何从 wsdl 生成 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端为我提供了 wsdl 以生成 Web 服务.但是当我使用 wsdl.exe 命令时,它从中生成了 .cs 类.我在我的 Web 服务中使用了该类,当我向客户端提供 wsdl 时,它与他们的架构不匹配.实际上,我希望从 wsdl 自动生成 .asmx,以便我可以填写 web 方法.这样它将完全匹配他们的架构.希望有意义.

Client provided me the wsdl to generate the web service.But when I used the wsdl.exe command it generated the .cs class out of it. I consumed that class in my web service and when I provided the wsdl to client it didn't match their schema. Actually I want the .asmx to be automatically generated from the wsdl so that I could fill in the web method. So that it will exactly match their schema. Hope it make sense.

推荐答案

不幸的是,对于您正在寻找的内容,没有灵丹妙药的解决方案.您可以执行以下操作:

There isn't a magic bullet solution for what you're looking for, unfortunately. Here's what you can do:

  • 在 Visual Studio 命令提示符窗口中使用此命令创建接口类:

  • create an Interface class using this command in the Visual Studio Command Prompt window:

wsdl.exe yourFile.wsdl/l:CS/serverInterface
使用 VB 或 CS 作为您选择的语言.这将创建一个新的 .cs.vb 文件.

创建一个新的 .NET Web 服务项目.将现有文件导入您的项目 - 在上述步骤中创建的文件.

Create a new .NET Web Service project. Import Existing File into your project - the file that was created in the step above.

在代码视图中的 .asmx.cs 文件中,修改您的类:

In your .asmx.cs file in Code-View, modify your class as such:

 

 public class MyWebService : System.Web.Services.WebService, IMyWsdlInterface
 {    
     [WebMethod]
     public string GetSomeString()
     {
         //you'll have to write your own business logic 
         return "Hello SOAP World";
     }
 }

这篇关于如何从 wsdl 生成 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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