IRESS Quote - Web Services Version 4 Walkthrough

balecomputerΑσφάλεια

3 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

404 εμφανίσεις

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 secu
rity 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 O
K
:



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://betawebserv
ices.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 projec
t in the Solution Explorer and select
Add Service Reference
.



4.

The “Add Service Reference” dialog will appear.

S
pecify 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
IRESS
Service
reference:


5.

Now we need to modify some of the defau
lt 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 <system.serviceModel> section.

The default value
s

given to some of the elements under the <basicHttpBinding> 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
<endpoint> section

in the
app.config

file
.

6.

Set the text of Form1 to “I
RESS Quote
Example” and add the following controls to the form:



A new label named “Label1” with tex
t “IRESS UserName”



A new textbox named “IRESSUserName
TextBox




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 PasswordCh
ar property of the textbox to *.



A new label named “Label4” with text “
Security




A new textbox named “
SecurityText
Box




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 “Get
Quote
Button” with text “Get
Quote




A new DataGridView
named “QuoteDataGridView”
that will di
splay the
returned
quote information
.


We want to add all output columns for the
PricingQuote
Ex
Get

method into the DataGridView control.
T
he easiest way to do this is by going to the Visual Studio menu
Data | Show Data Sources
. Then
drill down the data sou
rces to
PricingQuote
Ex
Get
Output
, expand this and you should then see
Input

and
Result
. Drill down
Result
, select
DataRows

and drag the
Data
Rows data source onto the
DataGridView control.





Arrange the controls
on Form1
in a similar fashion to the followin
g:


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 c
reate 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

IRE
SSService
.
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
.
IRESSSessionStartInp
ut

=
New

IRESSService
.
IRESSSessionStartInput
()



' Initialize the parameters of our IRESS session


issRequest
.
Parameters

=
New

IRESSService
.
IRESSSessionStartInputParameters
()


issRequest
.
Parameters
.
UserName

=
IRESSUserNameT
extBox
.
Text


issRequest
.
Parameters
.
CompanyName

=
CompanyTextBox
.
Text


issRequest
.
Parameters
.
Password

=
PasswordTextBox
.
Text


issRequest
.
Parameters
.
ApplicationID

=
"IRESSQuoteV4Example"



' Call the IRESSSessionSt
art 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

Exc
eption
(
"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



' Retrie
ve 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

= 2
5
' Timeout after 25
seconds


pqgeRequest
.
Header
.
PageSize

= 1000
' Recommended maximum
page size


pqgeRequest
.
Header
.
Updates

=
False

' Don't watch for
updates


pqgeRequest
.
Header
.
WaitForRespons
e

=
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



' Initiali
ze 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
.
Sec
urityCodeArray

=
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

IRESSS
ervice
.
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 f
or 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

pqgeResu
lt
.
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
(
"Fai
led 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.