If your computer uses a Dynamic IP address and you plan to use SOAP to invoke operation, you should
add a SOAP header to your request to help authenticate it. You may also choose this approach to authenticate
your requests even if your IP address is static. You only need to make sure you use the same email address
when you registered.
All Xignite operations accept a SOAP Header simply named Header. This Header accepts three optional parameters.
- Username holds your system Username, which is the email address
you provided when registering for the service.
- Password is currently unused.
- Tracer is used for tracing your SOAP requests. See the Troubleshooting section for details.
To authenticate your request using SOAP headers, you need only provide a value for the Username parameter.
The technique to add a soap header to your SOAP request will depend on your development toolkit.
Adding Soap Headers to a SOAP Request in VisualStudio.Net
When you add a web reference to an Xignite service using VisualStudio.Net, the proxy class that is automatically
generated recognizes the optional SOAP Header and makes it easy for you to provide a value:
VB
'RemoteQuotes is the web reference to the XigniteQuotes service
'objRemoteQuote is an instance of the service proxy
Dim objRemoteQuote as New RemoteQuotes.XigniteQuotes()
'create an instance of the header
Dim objHeader As New RemoteQuotes.Header()
'assign your username
objHeader.Username = "me@myfirm.com"
'assign the header to the service proxy
objRemoteQuote.HeaderValue = objHeader
'you can then call any method
Dim objExtendedQuote as RemoteQuotes.ExtendedQuote = objRemoteQuote.GetQuote("MSFT")
C#
RemoteQuotes.XigniteQuotes objRemoteQuote = new RemoteQuotes.XigniteQuotes();
RemoteQuotes.Header objHeader = new RemoteQuotes.Header();
objHeader.Username = "me@myfirm.com";
objRemoteQuote.HeaderValue = objHeader;
RemoteQuotes.ExtendedQuote objExtendedQuote = objRemoteQuote.GetQuote("msft");
Adding Soap Headers to a SOAP Request in Apache Axis 1.4
In Axis 1.4, you must manually create the SOAP header and assign its values.
XigniteRealTime objRealTimeService = new XigniteRealTimeLocator();
XigniteRealTimeSoap objRealTimePort = objRealTimeService.getXigniteRealTimeSoap();
org.apache.axis.client.Stub s = (Stub) objRealTimePort;
javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.newDocument();
org.w3c.dom.Element elem = doc.createElementNS("
http://www.xignite.com/services/", "Header");
org.w3c.dom.Element elem2 = doc.createElementNS("
http://www.xignite.com/services/","Username");
elem2.appendChild(doc.createTextNode("me@myfirm.com"));
elem.appendChild(elem2);
elem2 = doc.createElementNS("
http://www.xignite.com/services/", "Password");
elem2.appendChild(doc.createTextNode("password"));
elem.appendChild(elem2);
elem2 = doc.createElementNS("
http://www.xignite.com/services/","Tracer");
elem2.appendChild(doc.createTextNode(""));
elem.appendChild(elem2);
SOAPHeaderElement she = new SOAPHeaderElement(elem);
s.setHeader(she);
Adding Soap Headers to a SOAP Request in Apache Axis2
In Axis2, you must manually create the SOAP header and assign its values. Depending on the service and operation you are calling the header class name may not be "Header1", modify the code accordingly. Note that to generate JAX-RPC code with Axis2 (recommended), you must use the wsld2java code generation tool. The most common code generation usage would be: wsdl2java -uri "http://www.xignite.com/xQuotes.asmx?WSDL" -s -ap. More info is available on the Axis2 site.
XigniteQuotesXigniteQuotesSoapStub stub = new XigniteQuotesXigniteQuotesSoapStub();
Header1 header = new Header1();
Header h = new Header();
h.setUsername("me@myfirm.com");
h.setPassword("");
header.setHeader(h);
GetQuotes getQuotes = new GetQuotes();
getQuotes.setSymbol("msft,aapl");
GetQuotesResponse response = stub.GetQuotes(getQuotes, header);
Adding Soap Headers to a SOAP Request in Apache Axis2 with JAX-WS
Axis2 also supports Web Service calls over JAX-WS, a newer implementation, and code utilizing the JAX-WS API may not be entirely compatible with ASP.NET 2.0 Web Services, due to their use of RPC/Encoded and lack of a JAX-WS binding for this. With this in mind, developing JAX-WS clients to consume Xignite Web Services is not recommended or supported, in that there is no workaround for marshalling SOAP objects which have no JAX-WS binding. Background information on the differences between JAX-WS and JAX-RPC is available from IBM developerWorks' Web Services site.
However, if you must use this API, some Xignite Web Services will work with JAX-WS with some additional modification. Axis2 requires JAX-WS client code be generated using the wsimport generation tool, and authenticating against Xignite Web Services will require the addition of the -XadditionalHeaders switch, so that the command will look something like:
wsimport -XadditionalHeaders http://www.xignite.com?xIndexComponents.asmx?WSDL
The generated code can be used similarly to the Axis2/JAX-RPC method:
XigniteIndexComponents service = new XigniteIndexComponents();
XigniteIndexComponentsSoap soap = service.getXigniteIndexComponentsSoap();
Header header = new ObjectFactory().createHeader();
header.setUsername("me@myfirm.com");
header.setPassword("");
Components components = soap.getIndexComponents("^GSPC", IdentifierTypes.SYMBOL, header);
PHP 5
$xignite_header = new SoapHeader('http://www.xignite.com/services/',
'Header', array("Username" => "me@myfirm.com",
"Password" => "YourPassword",
"Tracer" => ""));
$wsdl = new soapclient('http://www.xignite.com/xCurrencies.asmx?WSDL');
$wsdl->__setSoapHeaders(array($xignite_header));
$input_params = array('From' => "USD", 'To' => "PKR");
$result = $wsdl->GetRealTimeCrossRate($input_params);
if ($wsdl->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '<pre>';
}
else {
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
NuSoap PHP
$UserName = 'me@myfirm.com';
$Password = '';
$wsdl = 'http://www.xignite.com/xHistorical.asmx?wsdl';
$client = new soapclient($wsdl, true);
if($err = $client->getError())
echo '<h2>Constructor Error</h2><pre>'. $err. '</pre>';
$param = array(
'Identifier' => "MSFT",
'IdentifierType' => "Symbol",
'EndDate' => '05/23/2007',
'PeriodType' => "Day",
'Periods' => "2");
$header = '<Header xmlns="http://www.xignite.com/services/">'.
'<Username>'. $UserName. '</Username>'.
'<Password>'. $Password. '</Password>'.
'<Tracer>'.'</Tracer></Header>';
$result = $client->call('GetHistoricalQuotesAsOf', array('parameters' => $param),
'http://www.xignite.com/services/',
'http://www.xignite.com/services/GetHistoricalQuotesAsOf',
$header);
Flex 2/SOAP
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function onCreationComplete() : void
{
xigniteQuotes.addSimpleHeader("Header", "http://www.xignite.com/services/",
"Username","me@myfirm.com");
xigniteQuotes.GetQuickQuotes.send( "MSFT" );
}
]]>
</mx:Script>
<mx:WebService id="xigniteQuotes" wsdl="http://www.xignite.com/xQuotes.asmx?WSDL">
<mx:operation name="GetQuickQuotes" resultFormat="e4x"
fault="mx.controls.Alert.show(event.fault.faultString)"
result="mx.controls.Alert.show(event.result.toString())">
<mx:request>
<Symbol></Symbol>
</mx:request>
</mx:operation>
</mx:WebService>
</mx:Application>