`
primer_2004
  • 浏览: 124220 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

webservice系列教学(2)

阅读更多
4. 3 在asp中使用Jscript调用
需下载msSoapToolkit20.exe
引用:MSSOAP.SoapClient
    例程:
  1.  <%@ LANGUAGE = JScript %>  
  2. <HTML>  
  3. <HEAD>  
  4. <TITLE>webservice演示</TITLE>  
  5. </HEAD>  
  6. <BODY>  
  7.     <%   
  8.          var WSDL_URL = "http://server0/yundan/webservice1.asmx?WSDL"  
  9.            var a, b, res   
  10.            var soapclient   
  11.             a = 12  
  12.             b = 13       
  13.         soapclient = Server.CreateObject("MSSOAP.SoapClient")   
  14.         soapclient.ClientProperty("ServerHTTPRequest") = true    
  15. ‘在ASP中运行 需要设置ServerHTTPRequest选项   
  16. soapclient.mssoapinit("http://192.168.0.4/yundan/Service1.WSDL","Service1","Service1Soap","")   
  17.         res = soapclient.test(2,3)    
  18. %>  
  19. <h3>webservice 演示</h3>  
  20. <B>Result:</B> <%=res%><P><P>  
  21. </BODY>  
  22. </HTML>  
4. 4在asp中使用vbscript调用
需下载msSoapToolkit20.exe
引用:MSSOAP.SoapClient
    例程:
  1. <%@ LANGUAGE = VBScript %>  
  2. <HTML>  
  3. <HEAD>  
  4. <TITLE>webservie演示</TITLE>  
  5. </HEAD>  
  6. <BODY>  
  7. <%   
  8. Dim soapclient   
  9. Const WSDL_URL = "http://192.168.0.4/yundan/service1.wsdl"  
  10.     set soapclient = Server.CreateObject("MSSOAP.SoapClient")   
  11.     soapclient.ClientProperty("ServerHTTPRequest") = True   
  12.     soapclient.mssoapinit    
  13. http://192.168.0.4:8080/yundan/Service1.WSDL","Service1","Service1Soap",""   
  14. Dim res   
  15.         res = soapclient.test(23, 34)   
  16. %>  
  17. <h1>webservie演示</h1>  
  18. <B>Result:</B> <%=res%><P><P>  
  19. </BODY>  
  20. </HTML>  
4. 5使用C#调用
无需下载任何组件
新建项目Visual C#项目windows应用程序
在解决方案资源管理器中添加web引用,输入wsdl文件所在地址。
将web引用改名.
yundan.(service_name)即可引用
*需引用System.web.services*
例程:
  1. using System;   
  2. using System.Drawing;   
  3. using System.Collections;   
  4. using System.ComponentModel;   
  5. using System.Windows.Forms;   
  6. using System.Data;   
  7. namespace csharp   
  8. {   
  9.         public class Form1 : System.Windows.Forms.Form   
  10.         {   
  11.             private System.Windows.Forms.Label label1;   
  12.             private System.Windows.Forms.TextBox textBox1;   
  13.             private System.ComponentModel.Container components = null;   
  14.             public Form1()   
  15.             {   
  16.                 InitializeComponent();   
  17.             }   
  18.             protected override void Dispose( bool disposing )   
  19.             {   
  20.                 if( disposing )   
  21.                 {   
  22.                     if (components != null)    
  23.                     {   
  24.                         components.Dispose();   
  25.                     }   
  26.                 }   
  27.                 base.Dispose( disposing );   
  28.             }   
  29.             #region Windows Form Designer generated code   
  30.             private void InitializeComponent()   
  31.             {   
  32.                 this.label1 = new System.Windows.Forms.Label();   
  33.                 this.textBox1 = new System.Windows.Forms.TextBox();   
  34.                 this.SuspendLayout();    
  35.                 this.label1.AutoSize = true;   
  36.                 this.label1.Location = new System.Drawing.Point(88, 48);   
  37.                 this.label1.Name = "label1";   
  38.                 this.label1.Size = new System.Drawing.Size(91, 14);   
  39.                 this.label1.TabIndex = 0;   
  40.                 this.label1.Text = "Webservice演示";   
  41.                 this.textBox1.Location = new System.Drawing.Point(88, 128);   
  42.                 this.textBox1.Name = "textBox1";   
  43.                 this.textBox1.TabIndex = 1;   
  44.                 this.textBox1.Text = "textBox1";    
  45.                 this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);   
  46.                 this.ClientSize = new System.Drawing.Size(292, 273);   
  47.                 this.Controls.AddRange(new System.Windows.Forms.Control[]   
  48. {   
  49.                 this.textBox1,   
  50.                 this.label1   
  51. });   
  52.                 this.Name = "Form1";   
  53.                 this.Text = "C#Webservie演示";   
  54.                 this.Load += new System.EventHandler(this.Form1_Load);   
  55.                 this.ResumeLayout(false);   
  56.             }   
  57.             #endregion   
  58.             [STAThread]   
  59.             static void Main()    
  60.             {   
  61.                 Application.Run(new Form1());   
  62.             }   
  63.   
  64.             private void Form1_Load(object sender, System.EventArgs e)   
  65.             {   
  66.                 int str;   
  67.                 你的web引用的名字.Service1 cc=new 你的web引用的名字.Service1();   
  68.                 str=cc.test(123,324);   
  69.                 textBox1.Text=str.ToString();   
  70.             }   
  71.         }   
  72. }  
需下载msSoapToolkit20.exe
引用:MSSOAP.SoapClient
    例程:
  1. var WSDL_URL = "http://192.168.0.4/yundan/service1.wsdl"  
  2. WScript.echo("Connecting: " + WSDL_URL)   
  3. var Calc = WScript.CreateObject("MSSOAP.SoapClient")   
  4. Calc.mssoapinit(WSDL_URL, "", "", "")   
  5. var Answer   
  6. Answer = Calc.test(14,28)   
  7. WScript.Echo("14+28=" + Answer)   
将其存成domo.js文件,直接双击运行。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics