Microsoft .NET Clients
- To program web services into .NET applications using
Microsoft's Visual Studio .NET development environment is simple.
- Add a Web Reference to the project by selecting
'Web References' then right click and select 'Add Web Reference'
- Enter www.abctext.com webservices/session.asmx into the address bar then press enter
- Enter abctext.ws_Session into the
web reference name field and then click the Add Reference button. The
Session web service returns a GUID that you will need before you call our
SMS web service. This GUID is valid for 15 minutes and then you will need to
re-authenticate with us.
- Now add another web reference to your project and enter www.abctext.com/webservices/sms.asmx
into the address bar then press enter.
- Enter abctext.ws_SMS into the
web reference name field and then click the Add Reference button.
- Copy and paste one of the 2 code blocks shown below which will call the
web service.
Imports System
Imports System.Xml
Imports System.Web.Services
Module Client
Sub Main()
Try
' variable declarations
Dim oService As New abctext.ws_SMS.SMS
Dim oSession As New abctext.ws_Session.Session
Dim oHeader As New abctext.ws_SMS.AuthorizationHeader
Dim oSMSRecipient(0) As abctext.ws_SMS.SMSRecipient
Dim oSMSResponse As abctext.ws_SMS.SMSResponse
Dim oSMSRequest As New abctext.ws_SMS.SMSRequest
Dim sGUID As String
' Get a valid GUID from abctext.com
sGUID = oSession.StartSession(user, password)
' Set the SOAP Header
oHeader.SessionKey = sGUID
oService.AuthorizationHeaderValue = oHeader
' Prepare the object
With oSMSRequest
.Message = "A test message"
.Unicode = False
.Sender = "abctext.com"
.MessageType = abctext.ws_SMS.MessageType.Text
oSMSRecipient(0) = New abctext.ws_SMS.SMSRecipient
oSMSRecipient(0).Number = number
.Recipients = oSMSRecipient
End With
' Call the service
oSMSResponse = oService.QuickSend(oSMSRequest)
' Kill the Session with abctext.com
oSession.EndSession(sGUID)
Catch se As System.Web.Services.Protocols.SoapException
Console.WriteLine("Message : " & se.Detail.InnerText)
Console.WriteLine()
Catch we As System.Net.WebException
Console.WriteLine(we.Message)
Console.WriteLine()
Catch e As Exception
Console.WriteLine(e.Message)
Console.WriteLine()
End Try
End Sub
End Module
Imports System
Imports System.Xml
Imports System.Web.Services
Module Client
Sub Main()
Try
' variable declarations
Dim sXML As String
Dim oService As New abctext.ws_SMS.SMS()
Dim oSession As New abctext.ws_Session.Session()
Dim oHeader As New abctext.ws_SMS.AuthorizationHeader()
Dim oNode As XmlNode
Dim sGUID As String
Dim oDOM As New XmlDocument
Dim sNamespace As String
' Get a valid GUID from abctext.com
sGUID = oSession.StartSession(user,password)
' Set the SOAP Header
oHeader.SessionKey = sGUID
oService.AuthorizationHeaderValue = oHeader
' Build the XML
sNamespace = "http://sjmillerconsultants.com/sms/send"
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Send", sNamespace)
oDOM.InsertBefore(oNode, oDOM.DocumentElement)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Request", sNamespace)
oDOM.DocumentElement.AppendChild(oNode)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Recipients", sNamespace)
oDOM.DocumentElement.LastChild.AppendChild(oNode)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Recipient", sNamespace)
oNode.innerXml = "NUMBER"
oDOM.DocumentElement.childNodes(0).LastChild.AppendChild(oNode)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Message", sNamespace)
oNode.innerXml = "A test message"
oDOM.DocumentElement.LastChild.AppendChild(oNode)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Unicode", sNamespace)
oNode.innerXml = "0"
oDOM.DocumentElement.LastChild.AppendChild(oNode)
oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Sender", sNamespace)
oNode.innerXml = "abctext.com"
oDOM.DocumentElement.LastChild.AppendChild(oNode)
' Optional Schedule element (with date and time nodes) used for deferred delivery
'oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Schedule", sNamespace)
'oDOM.DocumentElement.AppendChild(oNode)
'oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Date", sNamespace)
'oNode.innerXml = "2002-11-18"
'oDOM.DocumentElement.LastChild.AppendChild(oNode)
'oNode = oDOM.CreateNode(XmlNodeType.Element, Nothing, "Time", sNamespace)
'oNode.innerXml = "18:00:00"
'oDOM.DocumentElement.LastChild.AppendChild(oNode)
' Get the XML
sXML = oDOM.innerXml
' Call the web service
oNode = oService.Send(sXML)
' Kill the Session with abctext.com
oSession.EndSession(sGUID)
Catch se As System.Web.Services.Protocols.SoapException
Console.WriteLine("Message: " & se.Detail.innerText)
Catch we As System.Net.WebException
Console.WriteLine(we.Message)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
End Module
Microsoft SOAP Toolkit Clients
To program web services using the SOAP Toolkit involves more work
due to the fact that our services enforce SOAP Headers. Fortunately, we've wrote the code for you. Write the code as shown below which will call the
web service and output the results.
Public Sub Main()
' variable declarations
Dim sXML As String
Dim oSerializer As New SOAPSerializer30
Dim oReader As SoapReader30
Dim oResult As IXMLDOMElement
Dim oFault As IXMLDOMElement
Dim oConnector As SoapConnector30
Const sNAMESPACE As String = "http://sjmillerconsultants.com/webservices"
Const sENDPOINT As String = "http://www.abctext.com/webservices/sms.asmx?WSDL"
Set oConnector = New HttpConnector30
oConnector.Property("EndPointURL") = sENDPOINT
' PROXY CODE START
' oConnector.Property("ProxyServer") = "IPADDRESS"
' oConnector.Property("ProxyUser") = "DOMAIN\ACCOUNT"
' oConnector.Property("ProxyPassword") = "PASSWORD"
' oConnector.Property("EnableAutoProxy") = True
' PROXY CODE END
oConnector.Connect
oConnector.Property("SoapAction") = "http://sjmillerconsultants.com/webservices/Send"
oConnector.BeginMessage
With oSerializer
.Init oConnector.InputStream
.StartEnvelope
.StartHeader
.StartHeaderElement "AuthorizationHeader",sNAMESPACE
.StartElement "SessionKey",sNAMESPACE
.WriteString GetSessionId
.EndElement
.EndHeaderElement
.EndHeader
.StartBody
.StartElement "Send",sNAMESPACE
.StartElement "sXML",sNAMESPACE
.WriteString GetXML
.EndElement
.EndElement
.EndBody
.EndEnvelope
End With
oConnector.EndMessage
Set oReader = New SoapReader30
oReader.Load oConnector.OutputStream
If Not oReader.Fault Is Nothing Then
MsgBox oReader.FaultString.Text
Else
MsgBox oReader.RpcResult.xml
End If
End Sub
Private Function GetSessionId() As String
Dim oSOAP As New SoapClient30
Dim sSessId As String
oSOAP.MSSoapInit "http://www.abctext.com/webservices/session.asmx?WSDL"
' PROXY CODE START
' oConnector.Property("ProxyServer") = "IPADDRESS"
' oConnector.Property("ProxyUser") = "DOMAIN\ACCOUNT"
' oConnector.Property("ProxyPassword") = "PASSWORD"
' oConnector.Property("EnableAutoProxy") = True
' PROXY CODE END
sSessId = oSOAP.StartSession("UserName","Password")
GetSessionId = sSessId
End Function
Private Function GetXML() As String
Dim oDOM As New DOMDocument30
Dim oNode As IXMLDOMElement
Dim oChildNode As IXMLDOMElement
Const sNAMESPACE As String = "http://sjmillerconsultants.com/sms/send"
Set oNode = oDOM.createNode(NODE_ELEMENT,"Send",sNAMESPACE)
oDOM.appendChild oNode
Set oNode = oDOM.createNode(NODE_ELEMENT,"Request",sNAMESPACE)
oDOM.documentElement.appendChild oNode
Set oNode = oDOM.createNode(NODE_ELEMENT,"Recipients",sNAMESPACE)
Set oChildNode = oDOM.createNode(NODE_ELEMENT,"Recipient",sNAMESPACE)
oChildNode.text = "NUMBER"
oNode.appendChild oChildNode
oDOM.documentElement.lastChild.appendChild oNode
Set oNode = oDOM.createNode(NODE_ELEMENT,"Message",sNAMESPACE)
oNode.text = "Test message"
oDOM.documentElement.childNodes(0).appendChild oNode
Set oNode = oDOM.createNode(NODE_ELEMENT,"Unicode",sNAMESPACE)
oNode.text = "0"
oDOM.documentElement.childNodes(0).appendChild oNode
Set oNode = oDOM.createNode(NODE_ELEMENT,"Sender",sNAMESPACE)
oNode.text = "abctext.com"
oDOM.documentElement.childNodes(0).appendChild oNode
GetXML = oDOM.xml
End Function