---
title: " webservice系列教学（2）"
author: "primer_2004"
date: "2007-11-05T23:09:38Z"
tags: []
slug: "webservice-2"
draft: false
lastmod: "2007-11-05T23:09:38Z"
id: 138246
url: "https://primer-2004.iteye.com/blog/138246"
---

4\. 3 在asp中使用Jscript调用  
需下载msSoapToolkit20.exe  
引用：MSSOAP.SoapClient  
    例程：

01. &lt;%@ LANGUAGE = JScript %&gt;
02. &lt;HTML&gt;
03. &lt;HEAD&gt;
04. &lt;TITLE&gt;webservice演示&lt;/TITLE&gt;
05. &lt;/HEAD&gt;
06. &lt;BODY&gt;
07. &lt;%
08. var WSDL\_URL = "http://server0/yundan/webservice1.asmx?WSDL"
09. 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. %&gt;
19. &lt;h3&gt;webservice 演示&lt;/h3&gt;
20. &lt;B&gt;Result:&lt;/B&gt; &lt;%=res%&gt;&lt;P&gt;&lt;P&gt;
21. &lt;/BODY&gt;
22. &lt;/HTML&gt;

4\. 4在asp中使用vbscript调用  
需下载msSoapToolkit20.exe  
引用：MSSOAP.SoapClient  
    例程：

01. &lt;%@ LANGUAGE = VBScript %&gt;
02. &lt;HTML&gt;
03. &lt;HEAD&gt;
04. &lt;TITLE&gt;webservie演示&lt;/TITLE&gt;
05. &lt;/HEAD&gt;
06. &lt;BODY&gt;
07. &lt;%
08. Dim soapclient
09. 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. %&gt;
17. &lt;h1&gt;webservie演示&lt;/h1&gt;
18. &lt;B&gt;Result:&lt;/B&gt; &lt;%=res%&gt;&lt;P&gt;&lt;P&gt;
19. &lt;/BODY&gt;
20. &lt;/HTML&gt;

4\. 5使用C#调用  
无需下载任何[组件](http://www.e2web.cn/search/index.aspx?q=%D7%E9%BC%FE)  
新建项目Visual C#项目[windows](http://www.e2web.cn/search/list.aspx?classname=windows)[应用程序](http://www.e2web.cn/search/index.aspx?q=%D3%A6%D3%C3%B3%CC%D0%F2)。  
在解决方案资源管理器中添加web引用,输入wsdl文件所在地址。  
将web引用改名.  
yundan.（service\_name）即可引用  
\*需引用System.web.services*  
例程：

01. using System;
02. using System.Drawing;
03. using System.Collections;
04. using System.ComponentModel;
05. using System.Windows.Forms;
06. using System.Data;
07. namespace csharp
08. {
09. 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. private void Form1\_Load(object sender, System.EventArgs e)
64. {
65. int str;
66. 你的web引用的名字.Service1 cc=new 你的web引用的名字.Service1();
67. str=cc.test(123,324);
68. textBox1.Text=str.ToString();
69. }
70. }
71. }

需下载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文件，直接双击运行。