IRESS Quote - Web Services Version 4 Walkthrough Visual Basic 2008 sample to retrieve IRESS Quote information

IRESS Quote - Web Services Version 4 Walkthrough Visual Basic 2008 sample to retrieve IRESS Quote information The purpose of this walkthrough is to b...
Author: Lillian Sanders
0 downloads 0 Views 437KB Size
IRESS Quote - Web Services Version 4 Walkthrough Visual Basic 2008 sample to retrieve IRESS Quote information

The purpose of this walkthrough is to build the following Windows Forms Application that will allow you to specify a comma separated list of security codes, exchanges and data sources to retrieve price quotes using the PricingQuoteExGet API method. The security, exchange and data source should be provided as matching triplets.

1. Create a new Visual Basic Windows Forms Application project and name it IRESSQuoteV4Example then hit OK:

2. Next we need to determine the full URL of the WSDL to provide later when adding a Service Reference. Visit the Web Services 4.0 Web Pages (i.e. http://betawebservices.iress.com.au/v4) via a Web browser and select the WSDL link. The WSDL generator will then be displayed. We then need to enter in our IRESS Username, Company and Password, and select “IRESS” as the Service, then click on the WSDL button:

Once the WSDL appears, copy the full URL of the WSDL page as this needs to be provided in the next step when adding a Service Reference. 3. We now need to add a Service Reference to the project. To do this in Visual Studio 2008, you need to right click on the project in the Solution Explorer and select Add Service Reference.

4. The “Add Service Reference” dialog will appear. Specify the full WSDL URL obtained in step 2 as the Address and hit the Go button. If the WSDL is successfully generated the Services list will be populated with a new service called “IRESSService”. Set the Namespace to “IRESSService” then hit the OK button.

The solution should now contain a new Service References folder with the IRESSService reference:

5. Now we need to modify some of the default values added to the app.config file after the Service Reference was added. Open up the app.config file in the solution and look for the section. The default values given to some of the elements under the section are too restrictive. So the following elements need to be increased to the specified value otherwise errors will occur when attempting to run the sample: maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxNameTableCharCount="2147483647" Also the default Web Server endpoint URL can be specified under the address element in the section in the app.config file. 6. Set the text of Form1 to “IRESS Quote Example” and add the following controls to the form: ▪

A new label named “Label1” with text “IRESS UserName”



A new textbox named “IRESSUserNameTextBox”



A new label named “Label2” with text “Company”



A new textbox named “CompanyTextBox”



A new label named “Label3” with text “Password”.



A new textbox named “PasswordTextBox” and set the PasswordChar property of the textbox to *.



A new label named “Label4” with text “Security”



A new textbox named “SecurityTextBox”



A new label named “Label5” with text “Exchange”



A new textbox named “Exchange TextBox”



A new label named “Label6” with text “Web Services URL”



A new textbox named “WebServicesURLTextBox”



A new label named “Label7” with text “Data Source”



A new textbox named “DataSourceTextBox”



A new button named “GetQuoteButton” with text “Get Quote”



A new DataGridView named “QuoteDataGridView” that will display the returned quote information. We want to add all output columns for the PricingQuoteExGet method into the DataGridView control. The easiest way to do this is by going to the Visual Studio menu Data | Show Data Sources. Then drill down the data sources to PricingQuoteExGetOutput, expand this and you should then see Input and Result. Drill down Result, select DataRows and drag the DataRows data source onto the DataGridView control.



Arrange the controls on Form1 in a similar fashion to the following:

7. Add the code behind Form1 to retrieve and display quote information. The main bit of code which retrieves quote information from IRESS is all contained within the GetQuoteButton_Click event handler. The idea behind what we are doing is that we first create an IRESS session, then with the IRESS session key we can make requests to IRESS to retrieve quote information for the specified list of security codes, exchanges and data sources. Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' By default use the Web Services URL that was used to generate the WSDL stored in our application settings Dim ws As IRESSService.IRESSSoapClient = New IRESSService.IRESSSoapClient ' Define a Web Service instance WebServicesURLTextBox.Text = ws.Endpoint.Address.ToString() ' The endpoint URL is defined in app.config once the Service Reference has been added SecurityTextBox.Text = "BHP,CEN" ExchangeTextBox.Text = "ASX,NZ" DataSourceTextBox.Text = "" End Sub Private Sub GetQuoteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetQuoteButton.Click Try ' Define a Web Service instance Dim ws As IRESSService.IRESSSoapClient = New IRESSService.IRESSSoapClient ' Set the Web Service URL ws.Endpoint.Address = New System.ServiceModel.EndpointAddress(WebServicesURLTextBox.Text) ' Set the Web Services request timeout to 30 seconds (greater than IDS request timeout) ws.Endpoint.Binding.ReceiveTimeout = New TimeSpan(0, 0, 30) ' Create an IRESS session using the IRESSSessionStart method

Dim issRequest As IRESSService.IRESSSessionStartInput = New IRESSService.IRESSSessionStartInput() ' Initialize the parameters of our IRESS session issRequest.Parameters = New IRESSService.IRESSSessionStartInputParameters() issRequest.Parameters.UserName = IRESSUserNameTextBox.Text issRequest.Parameters.CompanyName = CompanyTextBox.Text issRequest.Parameters.Password = PasswordTextBox.Text issRequest.Parameters.ApplicationID = "IRESSQuoteV4Example" ' Call the IRESSSessionStart method to create the IRESS session (equivalent to logging in via the front-end) Dim issResult As IRESSService.IRESSSessionStartOutput = ws.IRESSSessionStart(issRequest) If IsNothing(issResult) Then Throw New Exception("Failed to start IRESS session") End If ' Obtain the IRESS session key from the response of the IRESSSessionStart method Dim strIRESSSessionKey = issResult.Result.DataRows(0).IRESSSessionKey ' Retrieve quote information using the PricingQuoteExGet method Dim pqgeRequest As IRESSService.PricingQuoteExGetInput = New IRESSService.PricingQuoteExGetInput ' Initialize the header, use the IRESS session key we got earlier pqgeRequest.Header = New IRESSService.PricingQuoteExGetInputHeader() pqgeRequest.Header.SessionKey = strIRESSSessionKey Dim guid As New Guid() ' Initialize the request options pqgeRequest.Header.Timeout = 25

' Timeout after 25

pqgeRequest.Header.PageSize = 1000

' Recommended maximum

pqgeRequest.Header.Updates = False

' Don't watch for

seconds page size updates pqgeRequest.Header.WaitForResponse = False ' Request to IRESS asynchronously to ensure method call does not timeout pqgeRequest.Header.RequestID = guid.NewGuid.ToString() ' Set the request identifier to identify our request when we page through results ' Initialize the request parameters - set the list of security codes, exchange and data sources to retrieve quotes for pqgeRequest.Parameters = New IRESSService.PricingQuoteExGetInputParameters() If Trim(SecurityTextBox.Text) = "" Then MsgBox("Please specify a comma-separated list of securities.", MsgBoxStyle.Critical) Exit Sub End If Dim saSecurityCode() As String = SecurityTextBox.Text.Split(",") pqgeRequest.Parameters.SecurityCodeArray = saSecurityCode

Dim saExchange() As String = Nothing If ExchangeTextBox.Text "" Then saExchange = ExchangeTextBox.Text.Split(",") End If If IsNothing(saExchange) = False Then pqgeRequest.Parameters.ExchangeArray = saExchange End If Dim saDataSource() As String = Nothing If DataSourceTextBox.Text "" Then saDataSource = DataSourceTextBox.Text.Split(",") End If pqgeRequest.Parameters.DataSourceArray = saDataSource Dim arrPriceRows As List(Of IRESSService.PricingQuoteExGetDataRow) = New List(Of IRESSService.PricingQuoteExGetDataRow) Dim pqgeResult As IRESSService.PricingQuoteExGetOutput ' Call the PricingQuoteExGet method until we have received all pages of data Do pqgeResult = ws.PricingQuoteExGet(pqgeRequest) ' Add data for each page into an array for display in our DataGridView later arrPriceRows.AddRange(pqgeResult.Result.DataRows) Application.DoEvents() ' Since we're in a loop allow processing of all windows messages in message queue Loop While pqgeResult.Result.Header.StatusCode = 1 ' Output all the data returned in the DataGridView on the main form using just a single line of code! QuoteDataGridView.DataSource = arrPriceRows Catch ex As Exception MsgBox("Failed to retrieve quote information. Error: " & ex.Message) End Try End Sub End Class

8. Compile and run the sample. 9. Fill in the IRESS Username, Company, Password, Security, Exchange, Web Services URL, and optionally the Data Source, and click the “Get Quote” button to retrieve quote information from IRESS.