Dec 10, 2007

Call Webservice Method Using MS SoapClient

Well, force to use asp to communicate with .NET webservices.
So, I choose the simplest way where I am using Microsoft Soap Client generic object to use my webservice method.

Here is my code:


dim soapclient
'// create SoapClient object
SET soapclient = CreateObject("MSSOAP.SoapClient")

'// set Server HTTP Request to true
SoapClient.ClientProperty("ServerHTTPRequest") = True

'// SOAP init with my webservice URL
Call Soapclient.mssoapinit("http://localhost/Elinkz_TestProject_TestService.asmx?wsdl")

'// GetTestData(xxx) is my webservices with param
response.write soapclient.GetTestData("myParamToMyWebservice")
response.end

-----------------------------------------------------------------------

GoogleSearch(Query, Start, MaxResults, Filter, Restrict, SafeSurf, Lr)
Dim Key
Key = "your key goes here"

Dim SoapClient
set SoapClient = Server.CreateObject("MSSOAP.SoapClient")

Dim NodeList
SoapClient.ClientProperty("ServerHTTPRequest") = True
SoapClient.mssoapinit "http://api.google.com/GoogleSearch.wsdl"
Set NodeList = SoapClient.doGoogleSearch(key, _
Query, Start, MaxResults, Filter,
Restrict, SafeSurf, Lr, "", "")

Set NodeList = Nothing
Set SoapClient = Nothing
End Function

-----------------------------------------------------------------------------

Function PerformGoogleSpellingSuggestion(Words)
Dim Key
Key = "your key goes here"

Dim SoapClient
set SoapClient = Server.CreateObject("MSSOAP.SoapClient")

Dim RetVal
SoapClient.ClientProperty("ServerHTTPRequest") = True
SoapClient.mssoapinit "http://api.google.com/GoogleSearch.wsdl"
RetVal = SoapClient.doSpellingSuggestion(Key, Words)

If RetVal > "" Then
Response.write RetVal
Else
Response.Write "No Suggestions"
End If

Set SoapClient = Nothing
End Function

-------------------------------------------------------------------------------

Function PerformGoogleGetCachedPage(Url)
Dim Key
Key = "your key goes here"

Dim SoapClient
Set SoapClient = Server.CreateObject("MSSOAP.SoapClient")

Dim RetVal
Dim DecodedPage
Dim i
dim NewArray

SoapClient.ClientProperty("ServerHTTPRequest") = True
SoapClient.mssoapinit "http://api.google.com/GoogleSearch.wsdl"
RetVal = SoapClient.doGetCachedPage(Key, Url)
NewArray = RetVal

for i = 1 to ubound(NewArray)
DecodedPage = DecodedPage & chr(ascB(MidB(NewArray, i, 1)))
next

Response.Write DecodedPage
Set SoapClient = Nothing
End Function

-------------------------------------------------------------------------------

You can use Google WS for free :) but only 1000 limit transaction per day!

No comments:

Post a Comment