Using SOAP Headers with the generated Proxy

Some services require SOAP headers to be passed as part of the request. Soap Headers tend to contain common content that is passes with many requests - typically some sort of authentication or session token. Depending on how these SOAP headers are published by the service you can access these headers indirectly.

If the Web Service publishes the SOAP header contract the .NET service proxy will generate the appropriate header properties as objects on the Proxy instance.

You can access these properties by creating an instance on main service proxy and setting:

Do TaxServiceProxy
loProxy = CREATE("TaxServiceProxy")

LOCAL loBridge as wwDotNetBridge
loBridge = loProxy.oBridge

LOCAL loService as TaxService.TaxService
loService = loProxy.oService

*** Create the SOAP header instance
? loBridge.CreateInstanceOnType(loService,"CredentialSoapHeaderValue","TaxService.CredentialSoapHeader")

*** Have to use indirect referencing because header is [ComVisible=false]
loBridge.SetPropertyEx(loService,"CredentialSoapHeaderValue.Username","me")
loBridge.SetPropertyEx(loService,"CredentialSoapHeaderValue.Password","secret")

*** Make the service call
result = loProxy.HelloWorld()

? result
? loProxy.cErrorMsg
RETURN

In the code above the service includes Credential header that is used to pass username and password. The service publishes the headers as a class (CredentialSoapHeader) which you can create and then set properties on.

The above code is complicated a bit by a nasty quirk in the generated .NET code which marks the header object as ComVisible=False which means it can't be accessed via COM directly. IOW, the normal way to create an instance with loBridge.CreateInstance() and assigning the instance to to the service doesn't work because the value can't be assigned via COM. Rather you have to manipulate both the header and the properties indirectly via Reflection through .NET by using

loBridge.CreateInstanceOnType(loService,"CredentialSoapHeaderValue","TaxService.CredentialSoapHeader")

*** Have to use indirect referencing because header is [ComVisible=false]
loBridge.SetPropertyEx(loService,"CredentialSoapHeaderValue.Username","me")
loBridge.SetPropertyEx(loService,"CredentialSoapHeaderValue.Password","secret")

These operations handle the object creation and property assignments inside of .NET so that the assignments can be made.

Unknown Soap Headers

Note that not all services that include headers publish those headers in the contract and if the headers are not imported via contract the proxy cannot directly publish those SOAP headers. The only way to handle 'unknown' SOAP headers (ie. those not defined in the WSDL) is by directly utilizing .NET and modifying the proxy or proxy startup code generated. More info.


© West Wind Technologies, 2004-2020 • Updated: 02/09/18
Comment or report problem with topic