Data Access Worldwide Knowledge Base
Article ID 2119 Article Title HOWTO: Modifying the soap:header area Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2119 KBase Category VDF11 Date Created 05/06/2005 Last Edit Date 05/06/2005
Article Text
QUESTION:
I need to add a license key to the soap:header area like in the example below.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<LicenseInfo xmlns="http://ws.strikeiron.com">
<LicenseKey>string</LicenseKey>
</LicenseInfo>
</soap:Header>
<soap:Body>
<GetCityState xmlns="http://www.strikeiron.com">
<ZipCode>string</ZipCode>
</GetCityState>
</soap:Body>
</soap:Envelope>
Any ideas on how I do this in Visual DataFlex?
ANSWER:
In the generated class you can augment the function CreateSoapBody. This function is called with a handle to the created XML document. Before forwarding the function, call a new function CreateSoapHeader that inserts the header information into the existing XML document. After adding your own header, forward the CreateSoapBody to allow VDF to do the normal stuff. Within the CreateSoapHeader function you can manipulate the XML document in a normal way.
Below is an example of how to use it:
use cClientWebService.pkg
Class cWSMatterLoadService is a cClientWebService
Procedure Construct_object
...
End_Procedure // Construct_object
//
// Function wsCreate
//
Function wsCreate handle llmatter string llstartDate returns string
...
End_Function // wsCreate
// New function to add userlogin information to the XML document
Function CreateSoapHeader Integer hoEnv Returns Boolean
Handle hoHeader hoUser
string sSoapEnvNsURI sSoapEnvNsPre sSoapEncodingNsUri
Integer eSoapEncoding
Boolean bOk
String sNameSpace
Get peSoapEncoding to eSoapEncoding
Get psSoapEnvNsURI to sSoapEnvNsURI
Get psSoapEnvNsPre to sSoapEnvNsPre
Get AddElementNS of hoEnv sSoapEnvNsURI (sSoapEnvNsPRE - ":Header") "" to hoHeader
If not hoHeader function_return 0
// if encoding, must add soap encoding style attribute
If (eSoapEncoding=seEncoded) begin
get psSoapEncodingNsUri to sSoapEncodingNsUri
Send AddAttributeNS of hoEnv sSoapEnvNsURI "encodingStyle" sSoapEncodingNsUri
end
Get psRequestNSURI to sNameSpace
Get AddElementNS Of hoHeader sNameSpace "user" "sa" To hoUser
Send Destroy Of hoUser
Send Destroy of hoHeader
Function_Return boK
End_Function // CreateSoapHeader
// Augmented function to insert a soap header into the XML document
Function CreateSoapBody integer hoEnv returns boolean
Boolean bOk
Get CreateSoapHeader hoEnv To bOk
Forward Get CreateSoapBody hoEnv To bOk
Function_Return bOk
End_Function // CreateSoapBody
End_Class // cWSMatterLoadService
If the service also returns a soap header in its response, you need to take one step further: since that is not what VDF expects (it expects the first child in the envelope to be the "soap:body" part), the generated classes will complain about the service returning an invalid XML. To fix that you can augment the DoSetSoapReturn function to have it call a
RemoveSoapHeader function before you can forward the DoSetSoapReturn.
Contributed By:
Emil Stojanov
email: EmilS@Quantaris.nl
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.