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

4．7使用vb.net调用  
无需下载任何[组件](http://www.e2web.cn/search/index.aspx?q=%D7%E9%BC%FE)  
新建项目Visual Basic项目[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.  
yundan.（service\_name）即可引用  
\*需引用System.web.services*  
例程：

01. Public Class Form1
02. Inherits System.Windows.Forms.Form
03. #Region " Windows 窗体设计器生成的代码 "
04. Public Sub New()
05. MyBase.New()
06. InitializeComponent()
07. End Sub
08. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
09. If disposing Then
10. If Not (components Is Nothing) Then
11. components.Dispose()
12. End If
13. End If
14. MyBase.Dispose(disposing)
15. End Sub
16. Private components As System.ComponentModel.IContainer
17. Friend WithEvents Label1 As System.Windows.Forms.Label
18. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
19. &lt;System.Diagnostics.DebuggerStepThrough()&gt; Private Sub InitializeComponent()
20. Me.Label1 = New System.Windows.Forms.Label()
21. Me.TextBox1 = New System.Windows.Forms.TextBox()
22. Me.SuspendLayout()
23. Me.Label1.AutoSize = True
24. Me.Label1.Location = New System.Drawing.Point(96, 40)
25. Me.Label1.Name = "Label1"
26. Me.Label1.Size = New System.Drawing.Size(91, 14)
27. Me.Label1.TabIndex = 0
28. Me.Label1.Text = "Webservice演示"
29. Me.TextBox1.Location = New System.Drawing.Point(88, 144)
30. Me.TextBox1.Name = "TextBox1"
31. Me.TextBox1.TabIndex = 1
32. Me.TextBox1.Text = "TextBox1"
33. Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
34. Me.ClientSize = New System.Drawing.Size(292, 273)
35. Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Label1})
36. Me.Name = "Form1"
37. Me.Text = "VB.net webserive演示"
38. Me.ResumeLayout(False)
39. End Sub
40. #End Region
41. Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
42. Dim cc As yundan.Service1 = New yundan.Service1()
43. TextBox1.Text = cc.test(12, 123)
44. End Sub
45. End Class

4．8使用vb6.0调用  
需下载msSoapToolkit20.exe  
添加引用：Microsoft Soap Type Library  
位置:”C:\\Program Files\\Common Files\\MSSoap\\Binaries\\ MSSOAP1.dll”  
    调用方法：  
    Dim cc As New MSSOAPLib.SoapClient  
    例程：  
    新建工程标准EXE添加3个textbox[控件](http://www.e2web.cn/search/index.aspx?q=%BF%D8%BC%FE)，text1,text2,text3添加一个button控件Command1  
    代码如下：

1. Option Explicit
2. Dim cc As New MSSOAPLib.SoapClient
3. Private Sub Command1\_Click()
4. cc.mssoapinit "http://192.168.0.4/yundan/Service1.asmx?WSDL"
5. Me.Text3.Text = cc.test(CInt(Text1.Text), CInt(Text2.Text))
6. End Sub

4．9使用vbscript调用  
需下载msSoapToolkit20.exe  
引用：MSSOAP.SoapClient  
    例程：

1. Option Explicit
2. Const WSDL\_URL = "http://192.168.0.4/yundan/service1.wsdl"
3. WScript.echo "Connecting: " & WSDL\_URL
4. Dim Calc
5. Set Calc = CreateObject("MSSOAP.SoapClient")
6. Calc.mssoapinit WSDL\_URL
7. Dim Answer
8. Answer = Calc.test(14,28)
9. WScript.Echo "14+28=" & Answer

将其存成domo.vbs文件，直接双击运行。

**4.10使用vc调用**  
需下载mssoaptoolkit20.exe  
    引用  
#import "msxml3.dll"  
using namespace msxml2;

#import "c:\\program files\\common files\\mssoap\\binaries\\mssoap1.dll" exclude("istream", "isequentialstream", "\_large\_integer", "\_ularge\_integer", "tagstatstg", "\_filetime") raw\_interfaces\_only  
using namespace mssoaplib;  
例程：  
新建工程àmfc appwizard(exe)\[ mclient]àstep1à基本对话à其他默认值即可  
修改源文件：

01. &lt; stdafx.h&gt;
02. // stdafx.h : include file for standard system include files,
03. //  or project specific include files that are used frequently, but
04. //      are changed infrequently
05. //
06. #if !defined(afx\_stdafx\_h\_\_045cd307\_9518\_4af1\_8ce3\_8ffe38d1acb2\_\_included\_)
07. #define afx\_stdafx\_h\_\_045cd307\_9518\_4af1\_8ce3\_8ffe38d1acb2\_\_included_
08. #if \_msc\_ver &gt; 1000
09. #pragma once
10. #endif // \_msc\_ver &gt; 1000
11. #define vc\_extralean        // exclude rarely-used stuff from windows headers
12. #include &lt;afxwin.h&gt;         // mfc core and standard components
13. #include &lt;afxext.h&gt;         // mfc extensions
14. #include &lt;afxdisp.h&gt;        // mfc automation classes
15. #include &lt;afxdtctl.h&gt;       // mfc support for internet explorer 4 common controls
16. #ifndef \_afx\_no\_afxcmn\_support
17. #include &lt;afxcmn.h&gt;         // mfc support for windows common controls
18. #endif // \_afx\_no\_afxcmn\_support
19. #import "msxml3.dll"
20. using namespace msxml2;
21. #import "c:\\program files\\common files\\mssoap\\binaries\\mssoap1.dll" exclude("istream", "isequentialstream", "\_large\_integer", "\_ularge\_integer", "tagstatstg", "\_filetime") raw\_interfaces\_only
22. using namespace mssoaplib;
23. #define msg(message) \\
24. { \\
25. ::messagebox(null,\_t(message),null,mb\_ok | mb\_iconexclamation| mb\_applmodal);\\
26. goto cleanup; \\
27. }
28. #define check\_hresult(hr, message) \\
29. if (failed(hr)) \\
30. { \\
31. msg(message); \\
32. }
33. //{{afx\_insert\_location}}
34. // microsoft visual c++ will insert additional declarations immediately before the previous line.
35. #endif // !defined(afx\_stdafx\_h\_\_045cd307\_9518\_4af1\_8ce3\_8ffe38d1acb2\_\_included\_)
36. &lt;mclient.h&gt;
37. // mclient.h : main header file for the mclient application
38. //
39. #if !defined(afx\_mclient\_h\_\_9a397da6\_5a62\_4aef\_be5e\_6c7629322ecc\_\_included\_)
40. #define afx\_mclient\_h\_\_9a397da6\_5a62\_4aef\_be5e\_6c7629322ecc\_\_included_
41. #if \_msc\_ver &gt; 1000
42. #pragma once
43. #endif // \_msc\_ver &gt; 1000
44. #ifndef \_\_afxwin\_h\__
45. #error include 'stdafx.h' before including this file for pch
46. #endif
47. #include "resource.h"       // main symbols
48. /////////////////////////////////////////////////////////////////////////////
49. // cmclientapp:
50. // see mclient.cpp for the implementation of this class
51. //
52. class cmclientapp : public cwinapp
53. {
54. public:
55. cmclientapp();
56. // overrides
57. // classwizard generated virtual function overrides
58. //{{afx\_virtual(cmclientapp)
59. public:
60. virtual bool initinstance();
61. //}}afx\_virtual
62. // implementation
63. //{{afx\_msg(cmclientapp)
64. // note - the classwizard will add and remove member functions here.
65. //    do not edit what you see in these blocks of generated code !
66. //}}afx\_msg
67. declare\_message\_map()
68. };
69. /////////////////////////////////////////////////////////////////////////////
70. //{{afx\_insert\_location}}
71. // microsoft visual c++ will insert additional declarations immediately before the previous line.
72. #endif // !defined(afx\_mclient\_h\_\_9a397da6\_5a62\_4aef\_be5e\_6c7629322ecc\_\_included\_)