|
Invoking .NET Web Services from Mobile Devices Part 1 of 2, by Derek Ferguson
WSJ Vol 02 Issue 01 - pg.41
Listing 1
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.NET
Imports System.Text.RegularExpressions
<WebService(Namespace:="
<a href="http://xb.com/webservices/" EUDORA=AUTOURL>
http://xb.com/webservices/</a>")>
Public Class Service1 Inherits System.Web.Services.WebService
<WebMethod(),SoapRpcMethod()> Public Function getQuote(ByVal
symbol As String) As String
Dim hwreq As HttpWebRequest
Dim hwres As HttpWebResponse
Dim inStream As System.IO.Stream
Dim strResponse As String
Dim rgExp As Regex
Dim m As Match
m = rgExp.Match(symbol, "[a-zA-Z]{4}")
If m.Success Then
hwreq =
CType(WebRequest.Create("
<a href="http://finance.lycos.com/home/stocks/quotes.asp?symbols=" EUDORA=AUTOURL>
http://finance.lycos.com/home/stocks/quotes.asp?symbols=</a>"
& symbol), HttpWebRequest)
hwres = CType(hwreq.GetResponse(), HttpWebResponse)
inStream = hwres.GetResponseStream()
Try
Do While True
strResponse = strResponse & Chr(inStream.ReadByte())
Loop
Catch ex As Exception
End Try
inStream.Close()
Dim temp As String
m = rgExp.Match(strResponse, "(?:Last Sale.*)\d+\.\d+",
RegexOptions.Singleline)
If m.Success Then
temp = m.Value()
m = rgExp.Match(temp, "\d+\.\d+", RegexOptions.Singleline)
If m.Success Then
getQuote = m.Value()
Exit Function
End If
End If
End If
throw new Exception("Invalid stock symbol!")
End Function
End Class
Listing 2
Private Sub Command1_Click()
Dim strRequest As String, strResponse As String
Dim psEnvelope As PocketSOAP.CoEnvelope
Dim psTransport As PocketSOAP.IHTTPTransportAdv
Set psEnvelope = CreateObject("PocketSOAP.Envelope")
Set psTransport = CreateObject("PocketSOAP.HTTPTransport")
psEnvelope.MethodName = "getQuote"
psEnvelope.URI = "
<a href="http://xb.com/webservices/" EUDORA=AUTOURL>
http://xb.com/webservices/</a>"
psEnvelope.CreateParameter "symbol", Text1.Text
strRequest = psEnvelope.Serialize
MsgBox strRequest
psTransport.SOAPAction = "
<a href="http://xb.com/webservices/getQuote" EUDORA=AUTOURL>
http://xb.com/webservices/getQuote</a>"
psTransport.Timeout = 99999
psTransport.Send
"<a href="http://localhost/Chapter10Server/Service1.asmx" EUDORA=AUTOURL>
http://localhost/Chapter10Server/Service1.asmx</a>", strRequest
strResponse = psTransport.Receive
psEnvelope.parse (strResponse)
MsgBox psEnvelope.Parameters.Item(0).Value
End Suba
|