본문 바로가기
프로그래밍/SOAP

Soap

by 백룡화검 2010. 4. 24.

Simple Object Access Protocol (SOAP)

The Simple Object Access Protocol (SOAP) is a lightweight protocol for exchanging information in a decentralized, distributed environment. SOAP runs on top of HTTP, so it can be easily integrated into existing web-based applications, and into existing corporate systems, since most firewalls allow communication on the standard HTTP port. As SOAP is an XML format, the results of queries are easily rendered using XSLT or other XML publishing tools.

The following is an iTQLTM query, represented as a SOAP message, ready for sending to a KowariTM server's SOAP endpoint.

 <?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:executeQueryToString
xmlns:ns1="http://mysite.com:8080/webservices/services/ItqlBeanService"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<queryString xsi:type="xsd:string">select $s $p $o from
<rmi://mysite.com/server1#> where $s $p $o;</queryString>
</ns1:executeQueryToString>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

Note - In the above SOAP example, replace mysite.com with the host name for your system.

Sending this query to a SOAP endpoint results in the query being executed, and the results returned. The following is an example of this using Visual Basic® code.

 

Public Function ExecuteQuery(ByVal server, _
ByVal Query As String) As String

Rem External tools

Dim Serializer As SoapSerializer30
Dim Reader As SoapReader30
Dim Connector As SoapConnector30

Dim EndPointURL As String
Dim NameSpace As String

EndPointURL = server & "/webservices/services/ItqlBeanService"
NameSpace = "http://org.tucana/itql"

Rem Make the connection
Set Connector = New HttpConnector30

Rem Initialise the properties
Connector.Property("Timeout") = 0
Connector.Property("EndPointURL") = EndPointURL
Connector.Property("SoapAction") = "executeQueryToString"

Rem Connect and create the envelope
Connector.Connect
Connector.BeginMessage

Set Serializer = New SoapSerializer30
Serializer.Init Connector.InputStream

Serializer.StartEnvelope
Serializer.SoapAttribute "xsi", , "http://www.w3.org/1999/XMLSchema-instance", "xmlns"
Serializer.SoapAttribute "xsd", , "http://www.w3.org/1999/XMLSchema", "xmlns"
Serializer.StartBody
Serializer.StartElement Method, NameSpace, "http://schemas.xmlsoap.org/soap/encoding/", "ns1"
Serializer.StartElement "queryString"
Serializer.SoapAttribute "type", , "xsd:string", "xsi"
Serializer.WriteString Query
Serializer.EndElement
Serializer.EndElement
Serializer.EndBody
Serializer.EndEnvelope
Connector.EndMessage

Set Reader = New SoapReader30

Rem Read the XML result
Reader.Load Connector.OutputStream

If Not Reader.Fault Is Nothing Then
Err.Raise vbObjectError + ERR_SOAP_FAULT, , Reader.FaultString.Text
Else
ExecuteQuery = Reader.RpcResult.Text
End If

Set Reader = Nothing
Set Serializer = Nothing
Set Connector = Nothing

End Function