代码环境: C# 、VS 2003
第一步;
创建一个web Service 如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace ws
{
///
/// Service1 的摘要说明。
///
public class AuthorsService : System.Web.Services.WebService
{
public AuthorsService()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键
[WebMethod]
public string HelloWorld()
{
return "你好 World";
}
}
}
二、使用WSDL,如下:
wsdl http://localhost/ws/service1.asmx /n:自定义命名空间,将生成的cs文件编译成dll文件
三、创建一个windows窗体控件工程,网上的例子比较多在此将不再多叙,将二中生成的cs和dll文件拷贝到工程目录下 在其中引用dll文件。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ComDw
{using Hello;
public class Thello:Hello.AuthorsService
{
} //using Hello;
///
/// UserControl1 的摘要说明。
///
public class Dwctrl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Dwctrl()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitComponent 调用后添加任何初始化
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(88, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(200, 23);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 96);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
//
// Dwctrl
//
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Dwctrl";
this.Size = new System.Drawing.Size(368, 168);
this.Load += new System.EventHandler(this.Dwctrl_Load);
this.ResumeLayout(false);
}
#endregion
private void Dwctrl_Load(object sender, System.EventArgs e)
{
Thello Test =new Thello();
this.label1.Text= Test.HelloWorld(); }
}
}
上面红色部分
四、编译代码如下:
C:csComDw>csc /out:xx.dll /target:library /R:System.Web.Services.dll AuthorsService.cs Dwctrl.cs
Microsoft (R) Visual C# .NET 编译器版本 7.10.3052.4
用于 Microsoft (R) .NET Framework 版本 1.1.4322
版权所有 (C) Microsoft Corporation 2001-2002。保留所有权利。
注意:上面南色部分为二中生成的cs文件 绿色部分为控件工程文件,编译后生成的文件为xx.dll
五、如下
说明:关于这方面的内容将继续探讨,希望大家多多帮我,我的QQ:470538520长时间在线
本文作者:http://yinzq.itpub.net/ 来源:西桥人家
CIO之家 www.ciozj.com 微信公众号:imciow