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à基本对话à其他默认值即可 修改源文件: < StdAfx.h> // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently //
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__045CD307_9518_4AF1_8CE3_8FFE38D1ACB2__INCLUDED_) <MClient.h> // MClient.h : main header file for the MCLIENT application //
#ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif
#include "resource.h" // main symbols
///////////////////////////////////////////////////////////////////////////// // CMClientApp: // See MClient.cpp for the implementation of this class //
class CMClientApp : public CWinApp { public: CMClientApp();
//{{AFX_MSG(CMClientApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() };
当前,像表格控件或用户界面控件这样的可重用软件组件,在市场上都占有很大的份额。但这类软件的重用有一个很大的限制,就是重用仅限于代码,数据不能重用。原因在于,发布组件甚至源代码都比较容易,但要发布数据就没那么容易,除非是不会经常变化的静态数据。 Web Service在允许重用代码的同时,可以重用代码背后的数据。使用Web Service,再也不必像以前那样,要先从第三方购买、安装软件组件,再从应用程序中调用这些组件;只需要直接调用远端的Web Service就可以了。举个例子,要在应用程序中确认用户输入的地址,只需把这个地址直接发送给相应的Web Service,这个Web Service 就会帮你查阅街道地址、城市、省区和邮政编码等信息,确认这个地址是否在相应的邮政编码区域。Web Service 的提供商可以按时间或使用次数来对这项服务进行收费。这样的服务要通过组件重用来实现是不可能的,那样的话你必须下载并安装好包含街道地址、城市、省区和邮政编码等信息的数据库,而且这个数据库还是不能实时更新的。 另一种软件重用的情况是,把好几个应用程序的功能集成起来。例如,要建立一个局域网上的门户站点应用,让用户既可以查询联邦快递包裹,查看股市行情,又可以管理自己的日程安排,还可以在线购买电影票。现在Web上有很多应用程序供应商,都在其应用中实现了这些功能。一旦他们把这些功能都通过Web Service “暴露”出来,就可以非常容易地把所有这些功能都集成到你的门户站点中,为用户提供一个统一的、友好的界面。 将来,许多应用程序都会利用Web Service,把当前基于组件的应用程序结构扩展为组件/Web Service 的混合结构,可以在应用程序中使用第三方的Web Service 提供的功能,也可以把自己的应用程序功能通过Web Service 提供给别人。两种情况下,都可以重用代码和代码背后的数据。
4.7使用vb.net调用 无需下载任何组件 Visualà项目à新建windows应用程序。àBasic项目 在解决方案资源管理器中添加web引用,输入wsdl文件所在地址。 将web引用改名为yundan. yundan.(service_name)即可引用 *需引用System.web.services* 例程: Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows 窗体设计器生成的代码 " Public Sub New() MyBase.New() InitializeComponent() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As System.ComponentModel.IContainer Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(96, 40) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(91, 14) Me.Label1.TabIndex = 0 Me.Label1.Text = "Webservice演示" Me.TextBox1.Location = New System.Drawing.Point(88, 144) Me.TextBox1.Name = "TextBox1" Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "TextBox1" Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Label1}) Me.Name = "Form1" Me.Text = "VB.net webserive演示" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cc As yundan.Service1 = New yundan.Service1() TextBox1.Text = cc.test(12, 123) End Sub 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 例程: 添加一个button控件Command1à添加3个textbox控件,text1,text2,text3à标准EXEà新建工程 代码如下: Option Explicit Dim cc As New MSSOAPLib.SoapClient Private Sub Command1_Click() cc.mssoapinit "http://192.168.0.4/yundan/Service1.asmx?WSDL" Me.Text3.Text = cc.test(CInt(Text1.Text), CInt(Text2.Text)) End Sub 4.9使用vbscript调用 需下载msSoapToolkit20.exe 引用:MSSOAP.SoapClient 例程: Option Explicit Const WSDL_URL = "http://192.168.0.4/yundan/service1.wsdl" WScript.echo "Connecting: " & WSDL_URL Dim Calc Set Calc = CreateObject("MSSOAP.SoapClient") Calc.mssoapinit WSDL_URL Dim Answer Answer = Calc.test(14,28) WScript.Echo "14+28=" & Answer 将其存成domo.vbs文件,直接双击运行。
// Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 129 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1009 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif <StdAfx.cpp> // stdafx.cpp : source file that includes just the standard includes // MClient.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" < MClient.cpp> // MClient.cpp : Defines the class behaviors for the application. //
BEGIN_MESSAGE_MAP(CMClientApp, CWinApp) //{{AFX_MSG_MAP(CMClientApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CMClientApp construction
CMClientApp::CMClientApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance }
///////////////////////////////////////////////////////////////////////////// // The one and only CMClientApp object
BOOL CMClientApp::InitInstance() { if (FAILED(::CoInitialize(NULL))) { return FALSE; }
AfxEnableControlContainer();
// Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.
#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif
CMClientDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }
::CoUninitialize();
// Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }