<%@ WebService language="VB" class="UPS" %> imports system imports system.web imports System.Net imports System.IO imports System.Web.Services imports Microsoft.VisualBasic Public Class UPS Public Function <WebMethod()> GetPrice(SvcCode as String,RateChart as String,ShipperZIP as String,ReceiverZIP as String, _ ReceiverCountry as String,PkgWeight as String,IsResidential as String,IsCOD as String, _ IsSatPickup as String,IsSatDelivery as String,PkgType as String) as string Dim sReturn as string = "" Dim WebReq as WebRequest Dim WebResp as WebResponse Dim strStream As StreamReader Dim URLRequest as String Dim line as string URLRequest = BuildUPSRequest(SvcCode,RateChart,ShipperZIP,ReceiverZIP,"US",PkgWeight,IsResidential,IsCOD,IsSatPickup,IsSatDelivery,PkgType) WebReq = WebRequestFactory.Create(URLRequest) WebResp = WebReq.GetResponse() strStream = new StreamReader(WebResp.GetResponseStream(), System.Text.Encoding.ASCII) Try line=strStream.ReadLine() do while line <> null line = strStream.ReadLine() If instr(1,lcase(line),"upsonline")<>0 then Dim strArrayData() as String strArrayData = Split(line,"%") if left(strArrayData(3),4)="0000" then sReturn = strArrayData(12) else sReturn = "ERR : " & right(strArrayData(3),len(strArrayData(3))-4) end if exit do end if loop Catch ex As Exception sReturn = "ERR : " & ex.Message End Try return sReturn end function Private Function BuildUPSRequest(SvcCode as String,RateChart as String,ShipperZIP as String,ReceiverZIP as String, _ ReceiverCountry as String,PkgWeight as String,IsResidential as String,IsCOD as String, _ IsSatPickup as String,IsSatDelivery as String,PkgType as String) as String Dim UPSPayload as String UPSPayload = "" UPSPayload = "http://www.ups.com/using/services/rave/qcost_dss.cgi?" UPSPayload = UPSPayload & "AppVersion=1.2&AcceptUPSLicenseAgreement=YES&" UPSPayload = UPSPayload & "ResponseType=application/x-ups-rss&ActionCode=3&" UPSPayload = UPSPayload & "ServiceLevelCode=" & SvcCode & "&RateChart=" & RateChart & "&" UPSPayload = UPSPayload & "ShipperPostalCode=" & ShipperZIP & "&ConsigneePostalCode=" & ReceiverZIP & "&" UPSPayload = UPSPayload & "ConsigneeCountry=" & ReceiverCountry & "&PackageActualWeight=" & PkgWeight & "&" UPSPayload = UPSPayload & "ResidentialInd=" & IsResidential & "&CODInd=" & IsCOD & "&SatDelivInd=" & IsSatDelivery UPSPayload = UPSPayload & "&SatPickupInd=" & IsSatPickup & "&PackagingType=" & PkgType return UPSPayload End function end class