SOAP WSDL: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) |
Cg (Diskussion | Beiträge) |
||
Zeile 9: | Zeile 9: | ||
To make a SOAP request as a client, given a WSDL (either as file, string or URL), |
To make a SOAP request as a client, given a WSDL (either as file, string or URL), |
||
you have to: |
you have to: |
||
* create a service |
* create a service from the WSDL |
||
* instantiate a client |
* instantiate a client |
||
* create a call object with call arguments |
* create a call object with call arguments |
Version vom 3. Juli 2015, 05:53 Uhr
Inhaltsverzeichnis
SOAP WSDL Package[Bearbeiten]
Basic Usage[Bearbeiten]
These chapter describes the basic underlying implementation. The code generated by the WSDL class generator calls those functions.
To make a SOAP request as a client, given a WSDL (either as file, string or URL),
you have to:
- create a service from the WSDL
- instantiate a client
- create a call object with call arguments
- perform the call
- extract the values from the returned result object
Creating a Service Instance[Bearbeiten]
You need a WSDL to create a service. This can come from multiple sources:
Service from URL (preferred)[Bearbeiten]
this is the preferred method, especially as it wil deal automatically with imported schema definitions (i.e. if the WSDL refers to other documents via an import)
service := SprayWSDLService onUrl: 'anUrlString'
Service from a String[Bearbeiten]
this only works, if the WSDL is self contained (eg. contains all required definitions and does not import other documents)
service := SprayWSDLService onXmlString: 'wsdlString'
From a set of Files/Strings[Bearbeiten]
when a WSDL URL is parsed, an transport object instance is used to fetch imported documents. By default, an instance of SptHTTPClient is used to fetch required documents. A mock transport class named SptHTTPLocalTransport can be used. This keeps a list of string documents variable and delivers that contents, when asked for. Thus, if you have a WSDL document, which imports other documents, AND you want to prevent WSDL fetches via http at runtime of you program, you can setup an instance of SptHTTPLocalTransport, give it all the documents (incl. any imported docs), and provide that as a document retriever. For example, if you have a WSDL in (urlA), which imports urlB and urlC, and urlC imports urlD, use the following setup:
localTransport := SptHTTPLocalTransport new.
localTransport localDocuments
at: urlA "eg something like: 'http://foo.services.de:30050/partner/PartnerBusinessService?SCHEMA'"
put:
'<?xml version="1.0"?>
... the whole urlA document as string...
'.
localTransport localDocuments
at: urlB "eg something like: 'http://foo.services.de..."
put:
'<?xml version="1.0"?>
... the whole urlB document as string...
'.
localTransport localDocuments
at: urlC "eg something like: 'http://foo.services.de..."
put:
'<?xml version="1.0"?>
... the whole urlC document as string...
'.
and create the service with:
definitions := WSDLDefinitions
onUrl: urlA
transport: localTransport.
service := SprayWSDLService onDefinitions: definitions.
Then, all required import urls will be fetched from there (eg. no HTTP requests required).
You can provide the url contents from class variables, class getter methods, etc. Of course, you can also read the documents from a local file, and setup the localTransport instance from their contents.
Instantiate a Client[Bearbeiten]
Once you have the service object, create a client to a concrete partner service with one of:
client := service createClient
to create a client to the services default host. This is the one as specified in the URL. Often, this is not the one you want to conenct to (for example, if you have a local test service running, and/or the host address of the service is different for in-house conenctions).
Then use:
client := service createClientTo:'http://foo.bar.com:4933/bla/...'.
Create a Call Object with Call Arguments[Bearbeiten]
Call argument objects fall into two categories:
- simple objects (which can be directy mapped to Smalltalk object)
- complex objects (in the schema, these are complexType elements)
Simple types are mapped to corresponding Smalltalk objects:
- xsd:string - String
- xsd:int - Integer
- xsd:integer - Integer
- xsd:boolean - Boolean
- xsd:date - Date
- xsd:time - Time
- etc.
Complex types must be represented as instances of one of:
- an XeQstruct - this is a special kind of Dictionary, which uses qualified names (eg. XML names with namespace and prefix) as keys. This is the default representation used by the SOAP framework.
- a Dictionary - if values are given as dictionary instance, it must contain key-value mappings for the sub-elements. The keys are the localName of the schema's element names (i.e. if the element is named foo:someType, then the key should be 'foo' only)
- a special data holder object - this must understand getter- and setter messages, corresponding to the local names of the elements