注冊 登錄
Office中國論壇/Access中國論壇 返回首頁

的個人空間 http://ctxi.cn/?0 [收藏] [復(fù)制] [分享] [RSS]

日志

【分享】在Access2003中使用Web Service

已有 2278 次閱讀2008-3-23 14:29 |個人分類:Access

10樓有例子下載


Web Service是個時(shí)尚的話題,在很多領(lǐng)域都有應(yīng)用,Access能否使用呢,回答是當(dāng)然的,下面我就用新浪提供的短信發(fā)送Web Service來給大家做過介紹,相信你們會喜歡的。

1.下載并安裝Microsoft Office 2003 Web Services Toolkit 2.01  下載地址:http://www.microsoft.com/downloa ... p;displaylang=zh-cn

2.添加對Microsoft Office Soap Type Library v3.0的引用,Microsoft Office Soap Type Library v3.0的dll文件位于:C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSSOAP30.DLL,隨 Microsoft Office 2003 System 一起安裝的。

3.打開Access至VBE,這時(shí)會在工具菜單的引用下面多一個Web服務(wù)引用。單擊web引用,打開web服務(wù)引用對話框。

4.單擊web服務(wù)URL單選鈕,在URL中輸入:http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl,單擊搜索按鈕,在搜索結(jié)果框中勾選SMSWS,然后單擊下方的添加按鈕。

5.這時(shí)Microsoft Office 2003 Web Services Toolkit會自動創(chuàng)建一個類模塊。類模塊內(nèi)容如下:

CODE:

*****************************************************************
'該類是由 Microsoft Office 2003 Web Services Toolkit 創(chuàng)建的。
'
'創(chuàng)建時(shí)間: 10/5/2007 12:41:01 AM
'
'說明:
'該類是 Web 服務(wù)
' 的 Visual Basic for Applications 類表示形式,這是由 http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl 定義的。
'
'使用:
'將變量聲明為新的 clsws_SMSWS,然后編寫代碼以
'使用該類所提供的方法。
'示例:
' Dim ExampleVar as New clsws_SMSWS
' debug.print ExampleVar.wsm_sendXml(“示例輸入”)
'
'有關(guān)更多信息,請參閱 Microsoft Office 2003
'Web Services Toolkit 幫助中的“復(fù)雜類型”。
'
'對此類中的代碼所做的更改可能導(dǎo)致錯誤的行為。
'
'*****************************************************************
'聲明專用類變量。
Private sc_SMSWS As SoapClient30
Private Const c_WSDL_URL As String = "http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl"
Private Const c_SERVICE As String = "SMSWS"
Private Const c_PORT As String = "SMSWebServiceSoapPort"
Private Const c_SERVICE_NAMESPACE As String = "http://outlook.microsoft.com/add-ins/SMS/wsdl/"
Private Sub Class_Initialize()
'*****************************************************************
'每次實(shí)例化該類時(shí)都將調(diào)用此子例程。
'將 sc_ComplexTypes 創(chuàng)建為新的 SoapClient30,然后
'用在
'http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl 中找到的 WSDL 文件實(shí)例化 sc_ComplexTypes.mssoapinit2。
'*****************************************************************
Dim str_WSML As String
str_WSML = ""
Set sc_SMSWS = New SoapClient30
sc_SMSWS.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
'使用 Internet Explorer 的 LAN 設(shè)置中定義的代理服務(wù)器,方法是
'將 ProxyServer 設(shè)置為
sc_SMSWS.ConnectorProperty("roxyServer") = ""
'如果 Internet Explorer 被設(shè)置為自動檢測,則自動檢測代理設(shè)置,
'方法是將 EnableAutoProxy 設(shè)置為真
sc_SMSWS.ConnectorProperty("EnableAutoProxy") = True

End Sub
Private Sub Class_Terminate()
'*****************************************************************
'將在每次析構(gòu)該類時(shí)調(diào)用此子例程。
'將 sc_ComplexTypes 設(shè)置為 Nothing。
'*****************************************************************
'錯誤捕獲
On Error GoTo Class_TerminateTrap
Set sc_SMSWS = Nothing
Exit Sub
Class_TerminateTrap:
SMSWSErrorHandler ("Class_Terminate")
End Sub
Private Sub SMSWSErrorHandler(str_Function As String)
'*****************************************************************
'此子例程是類錯誤處理程序。當(dāng)任何類子例程或函數(shù)
'遇到錯誤時(shí),都可以從該子例程或函數(shù)調(diào)用此子例程。然后,它將引發(fā)錯誤并提供
'調(diào)用子例程或函數(shù)的名稱。
'*****************************************************************
'SOAP 錯誤
If sc_SMSWS.FaultCode <> "" Then
Err.Raise vbObjectError, str_Function, sc_SMSWS.FaultString
'非 SOAP 錯誤
Else
Err.Raise Err.Number, str_Function, Err.Description
End If
End Sub
Public Function wsm_sendXml(ByVal str_Carrier As String, ByVal str_Id As String, ByVal str_Password As String, ByVal str_ToMobile As String, ByVal str_Message As String, ByVal str_MsgType As String) As String
'*****************************************************************
'從 http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl 創(chuàng)建的代理函數(shù)。
'*****************************************************************
'錯誤捕獲
On Error GoTo wsm_sendXmlTrap
wsm_sendXml = sc_SMSWS.sendXml(str_Carrier, str_Id, str_Password, str_ToMobile, str_Message, str_MsgType)
Exit Function
wsm_sendXmlTrap:
SMSWSErrorHandler "wsm_sendXml"
End Function
從代碼可以看出類模塊提供了一個公共方法wsm_sendXml,這就是我們需要的。

5.我們就可以通過下面的方法使用了:
DiDim ws As New clsws_SMSWS
ws.wsm_sendXml      。。。參數(shù)省略

參數(shù)說明:
carrier:運(yùn)營商名稱,這里面可以隨便輸,不過似乎沒有任何顯示,不知道里面有沒有其它奧秘。
userid:您在新浪無線上注冊的手機(jī)ID,即http://sms.sina.com.cn
password:您在新浪無線上注冊手機(jī)時(shí)所使用的密碼。
mobilenumber:對方的手機(jī)號碼;
content:發(fā)送短消息的內(nèi)容;
msgtype:發(fā)送短消息的類型,目前僅使用文本短信方式,使用的是“Text”。


資費(fèi)標(biāo)準(zhǔn)請參看新浪無線網(wǎng)站上的相關(guān)說明,應(yīng)該是一條一角錢,不過也或者是一條兩角線。由于其后臺可能使用了消息隊(duì)列機(jī)制,在繁忙的時(shí)候,可能會有幾秒鐘延遲。

[ 本帖最后由 fan0217 于 2007-10-6 12:09 編輯 ]

評論 (0 個評論)

facelist doodle 涂鴉板

您需要登錄后才可以評論 登錄 | 注冊

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2024-10-23 10:27 , Processed in 0.059517 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部