关于winform控件在IE浏览器引用webservice的一点经验(一)

代码环境: 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
{
 /// <summary>
 /// Service1 的摘要说明。
 /// </summary>
 public class AuthorsService : System.Web.Services.WebService
 {
  public  AuthorsService()
  {
   //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
   InitializeComponent();
  }

  #region 组件设计器生成的代码
  
  //Web 服务设计器所必需的
  private IContainer components = null;
    
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  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;
  /// <summary>
  /// UserControl1 的摘要说明。
  /// </summary>
  public class Dwctrl : System.Windows.Forms.UserControl
  {
   private System.Windows.Forms.Label label1;
   private System.Windows.Forms.Button button1;
   /// <summary>
   /// 必需的设计器变量。
   /// </summary>
   private System.ComponentModel.Container components = null;

   public Dwctrl()
   {
    // 该调用是 Windows.Forms 窗体设计器所必需的。
    InitializeComponent();

    // TODO: 在 InitComponent 调用后添加任何初始化

   }

   /// <summary>
   /// 清理所有正在使用的资源。
   /// </summary>
   protected override void Dispose( bool disposing )
   {
    if( disposing )
    {
     if( components != null )
      components.Dispose();
    }
    base.Dispose( disposing );
   }

   #region 组件设计器生成的代码
   /// <summary>
   /// 设计器支持所需的方法 - 不要使用代码编辑器
   /// 修改此方法的内容。
   /// </summary>
   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:/cs/ComDw>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

五、如下

<object id="drawcontrol" classid="http:xx.dll#ComDw.Dwctrl" height=300px width=400px VIEWASTEXT></object>

说明:关于这方面的内容将继续探讨,希望大家多多帮我,我的QQ:470538520长时间在线

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值