WSDL文件生成WEB service server端C#程序

一般一个已经实现功能的WEB Server会发布自己的WSDL文件,供客户端生成代理类。

 

但有时是先有的server与client交互的接口定义(WSDL)文件,然后由server和client端分别写程序,一个提供web服务,一个使用web服务。

以下介绍如何由已有的WSDL文件在VS2005中生成server端代码。

1)使用VS2005提供的工具wsdl.exe由WSDL文件生成cs文件:

使用wsdl.exe的/serverInterface选项(或缩写的 /si)指定输入的wsdl文件(注意,如果要转换的wsdl文件中import了其他wsdl文件,则所有文件都应列出,包括使用到的xsd文件也应列 出)。输出将是 一个代码文件(默认是C#的,如果需要别的语言,参考MSDN中wsdl.exe的使用说明),其中包含每个 wsdl 绑定的接口。

示例:假设ServerInterfaceSample.wsdl文件中import了importedSample.wsdl,并使用Service.xsd作为schema文件;

wsdl.exe /si ServerInterfaceSample.wsdl importedSample.wsdl Service.xsd

生成代码如下:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

//
// This source code was auto-generated by wsdl, Version=2.0.50727.42.
//


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Web.Services.WebServiceBindingAttribute(Name="org.csapi.cs.IpChargingManagerSOAPBinding", Namespace="http://www.csapi.org/cs/wsdl")]
public interface IOrgcsapicsIpChargingManagerSOAPBinding {
   
    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestElementName="org.csapi.cs.IpChargingManager.createChargingSession", RequestNamespace="http://www.csapi.org/cs/schema", ResponseElementName="org.csapi.cs.IpChargingManager.createChargingSessionResult", ResponseNamespace="http://www.csapi.org/cs/schema", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    orgcsapicsTpChargingSessionID createChargingSession([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] EndpointReferenceType appChargingSession, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string sessionDescription, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] orgcsapicsTpMerchantAccountID merchantAccount, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] orgcsapiTpAddress user, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] orgcsapicsTpCorrelationID correlationID);
   
    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestElementName="org.csapi.cs.IpChargingManager.createSplitChargingSession", RequestNamespace="http://www.csapi.org/cs/schema", ResponseElementName="org.csapi.cs.IpChargingManager.createSplitChargingSessionResult", ResponseNamespace="http://www.csapi.org/cs/schema", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    orgcsapicsTpChargingSessionID createSplitChargingSession([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] EndpointReferenceType appChargingSession, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string sessionDescription, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] orgcsapicsTpMerchantAccountID merchantAccount, [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)] orgcsapiTpAddress[] users, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] orgcsapicsTpCorrelationID correlationID);
   
    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestElementName="org.csapi.IpService.setCallback", RequestNamespace="http://www.csapi.org/osa/schema", ResponseElementName="org.csapi.IpService.setCallbackResult", ResponseNamespace="http://www.csapi.org/osa/schema", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    void setCallback([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] EndpointReferenceType appInterface);
   
    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestElementName="org.csapi.IpService.setCallbackWithSessionID", RequestNamespace="http://www.csapi.org/osa/schema", ResponseElementName="org.csapi.IpService.setCallbackWithSessionIDResult", ResponseNamespace="http://www.csapi.org/osa/schema", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    void setCallbackWithSessionID([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] EndpointReferenceType appInterface, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] int sessionID);
}

代码中有一个接口类,并给出了接口函数声明.

此功能的优点是将实现代码和协定代码(如接口所定义的那样)分开。 如果更改 wsdl,然后重新生成接口,则不会丢失任何实现代码。 若要遵循建议的设计指南,则不应将任何代码放置在更改 wsdl 协定的实现中。 同样,不应使用影响运行时行为的代码来更改接口。 协定和实现的详细信息应该分开。

2) 在VS IDE中新建一个web service工程,加入新生成的**Interface.cs文件.
将自动生成的Service类改为从加入的Interface接口类派生,并实现所有的接口函数.(注意名空间一致)

[WebService(Namespace = "http://www.csapi.org/cs/wsdl")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : IOrgcsapicsIpChargingManagerSOAPBinding
{
    public orgcsapicsTpChargingSessionID createChargingSession(EndpointReferenceType appChargingSession, string sessionDescription, orgcsapicsTpMerchantAccountID merchantAccount, orgcsapiTpAddress user,orgcsapicsTpCorrelationID correlationID)
    {
        return new orgcsapicsTpChargingSessionID();
    }

    public orgcsapicsTpChargingSessionID createSplitChargingSession(EndpointReferenceType appChargingSession, string sessionDescription, orgcsapicsTpMerchantAccountID merchantAccount, orgcsapiTpAddress[] users, orgcsapicsTpCorrelationID correlationID)
    {
        return new orgcsapicsTpChargingSessionID();
    }

    public void setCallback(EndpointReferenceType appInterface)
    {

    }

    public void setCallbackWithSessionID(EndpointReferenceType appInterface, int sessionID)
    {

    }
   
}

转载于:https://www.cnblogs.com/wenanry/archive/2011/12/31/2308162.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/261036.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php二维数组排序 按照指定的key 对数组进行排序

2019独角兽企业重金招聘Python工程师标准>>> /*** desc arraySort php二维数组排序 按照指定的key 对数组进行排序* param array $arr 将要排序的数组* param string $keys 指定排序的key* param string $type 排序类型 asc | desc* return array*/ function arrayS…

剑指Offer - 九度1367 - 二叉搜索树的后序遍历序列

剑指Offer - 九度1367 - 二叉搜索树的后序遍历序列2013-11-23 03:16 题目描述&#xff1a;输入一个整数数组&#xff0c;判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 输入&#xff1a;每个测试案例包…

13个代码注释的小技巧

13个代码注释的小技巧 这篇文章是由Jos M. Aguilar在他卓越的博客中以西班牙语的形式首发&#xff0c;其后Timm Martin在获得Aguilar先生的授权下&#xff0c;对该文章进行翻译、修改&#xff0c;并且在DevTopics上发布。 以下13个小技巧可以使得你的代码在长时间内依然能够保…

android webview onconsolemessage,Android WebView一些特殊的使用

在Android5.0之前&#xff0c;webView默认是允许加载混合网络协议内容的&#xff1b;在5.0以上&#xff0c;默认不允许加载http和https的混合内容if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {webView.getSettings().setMixedContentMode(WebSettings.MIXED…

让您的Xcode键字如飞

2019独角兽企业重金招聘Python工程师标准>>> 作者&#xff1a;吴白&#xff08;微博&#xff09; 手指在键盘上飞速跳跃,终端上的代码也随着飞舞,是的这确实很酷。优秀的程序员总是这么一群人&#xff0c;他们不拘于现状&#xff0c;不固步自封&#xff0c;他们喜欢…

【Android Developers Training】 6. 配置Action Bar

注&#xff1a;本文翻译自Google官方的Android Developers Training文档&#xff0c;译者技术一般&#xff0c;由于喜爱安卓而产生了翻译的念头&#xff0c;纯属个人兴趣爱好。 原文链接&#xff1a;http://developer.android.com/training/basics/actionbar/setting-up.html 配…

android 7 创建文件夹,Android 在 res/layout 文件夹 下创建一个 子文件夹实例

Android 资源文件夹 Layout 文件夹Layout文件是存放Android的布局文件的资源文件夹&#xff0c;但是如果你想要在里面创建子文件夹&#xff0c;你会发现xml文件报错。如何在Layout文件夹下方创建Layout的子文件夹。这边我们需要著一个一个点就是我们的Layout 文件夹是属于资源文…

一步一步学NUnit

转载&#xff1a;http://tech.sina.com.cn/s/2009-07-17/1129988785.shtml 单元测试基础知识 单元测试是开发者编写的一小段代码&#xff0c;用于检验被测代码的一个很小的、很明确的功能是否正确。通常而言&#xff0c;一个单元测试是用于判断某个特定条件(或者场景)下某个特定…

面向对象JS编程(一)——创建对象

1.普通模式 var person new Object();person.name "Laughing";person.age 28;person.job "Software Engineer";peron.sayName function(){ alert(this.name);};person.sayName(); 缺点&#xff1a;创建多个对象时&#xff0c;会产生大量的重复代码…

android功耗iphone,是心目中的安卓小屏旗舰吗?iPhone 8尺寸大小,4000mAh电池容量...

相信很多人都都喜欢小屏手机&#xff0c;但因为小屏手机总体需求不多&#xff0c;而且相对大屏更不好做&#xff0c;所以手机商都不愿意做小屏手机&#xff0c;这也导致市面上小屏手机非常少&#xff0c;苹果推出了iPhone 12 Mini&#xff0c;但是因为电池只有2200mAh&#xff…

mySQL 数据库错误

2019独角兽企业重金招聘Python工程师标准>>> java.sql.SQLException: The user specified as a definer (..%) does not exist 视图、存储过程的使用者若非其创建者&#xff0c;就会出现这样的错误 可以修改用户的权限或重新创建进行解决 转载于:https://my.oschina…

委托、事件的个人理解

事件&#xff1a;一个用event进行了封装的委托类型的变量&#xff0c;使得在进行注册的时候只能使用 或者- 需要一个触发者和一个执行者&#xff0c;类似于Observer模式中的Subject和Observer&#xff08;当一个对象的状态发生改变时&#xff0c;所有依赖于他的对象都会得到通知…

android 组建水平居中,Android开发借助LinearLayout实现垂直水平居中布局

释放双眼&#xff0c;带上耳机&#xff0c;听听看~&#xff01;在Android应用程序的开发中&#xff0c;有时需要限制水平和垂直屏幕的切换&#xff0c;今天这篇文章是技术狗小编为大家整理的Android应用借助LinearLayout实现垂直水平居中布局&#xff0c;希望对你学习这方面有所…

我不想再活在别人的世界里

我过多的关注别人的世界。 却没有去寻找属于自己的故事 总是犹豫着要不要出发 然后发现 一天就这么过去了。 转载于:https://www.cnblogs.com/zjjsxuqiang/p/3445392.html

面壁人VS智子 --- 搜索排序的作弊和反作弊

搜索引擎已经是目前网络流量最大入口&#xff0c;在大搜上&#xff0c;基本上大家打开网页做的第一件事情就是打开一个搜索引擎&#xff0c;然后键入你感兴趣的内容&#xff0c;然后开始浏览。如果是个电商的网站&#xff0c;你打开以后&#xff0c;基本上也是直接键入你感兴趣…

(转)网站推广优化教程100条(SEO,网站关键字优化,怎么优化网站,如何优化网站关键字)...

网站推广优化教程100条&#xff08;完整版)下面介绍新手建站推广完美教程&#xff0c;各位根据自己的实际情况酌情选用&#xff1a; 1、准备个好域名。①.尽量在5位数内&#xff0c;当然也不一定&#xff0c;反正要让用户好记。&#xff08;看个人&#xff09;&#xff1b;②.尽…

Android中attrs.xml文件的使用详解

$*********************************************************************************************$博主推荐&#xff1a;风萧兮兮易水寒&#xff0c;“天真”一去兮不复还。如何找到天真的那份快乐。小编倾力推荐app: 天真无谐下载方式&#xff1a;豌豆荚&#xff0c;应用宝…

细说JavaScript对象(1):对象的使用和属性

JavaScript 中的一切都可以视为对象&#xff0c;除了两个特例&#xff1a;null 和 undefined。 false.toString(); // false [1, 2, 3].toString(); // 1,2,3function Foo(){} Foo.bar 1; Foo.bar; // 1 一个经常容易被误解的就是数字常量不能视为对象&#xff0c;实际上数字常…

学习笔记:InnoDB存储结构及多版本实现

因为InnoDB是多版本化的数据库存储引擎, 它必须在表空间中保存关于旧版本数据行的信息。这个信息被存在名为rollback segment&#xff08;类似于Oracle中的回滚段&#xff09;的数据结构中。 在内部&#xff0c;InnoDB给数据库中的每一行添加三个域。一个是6字节的DB_TRX_ID域&…

access2003的使用

access2003中如何用sql语句创建表 http://zhidao.baidu.com/link?urldinVbwoI20Xz__NbcIeBPdkjeXRWmZNB0xJvdr0eMBqNflv_JcWgUoPw3ozFfqnTQ9FLkNv0XXs9loDR2Oc7Oq SQL 数据定义查询创建表&#xff1a; 第一张表&#xff08;藏书&#xff09; CREATE TABLE 藏书 (书号 Text(10)…