Вы находитесь на странице: 1из 34

WEB SERVICES IN PRACTICE

Prepared by StatusMart Team Version No. 1.0


Reviewed by Date SEP-10-2007

1
Table of Contents

I. Developing and Using a Web Service..............................................................3

II Consuming a Free Online Web Service available .....................................................16

III Case Study on Web Service(SM SendLoanFile).......................................................25

2
I. Developing and Using a Web Service

Steps for creating a simple web service

 Open Microsoft Visual Studio .NET from start Menu to open the Start page of Microsoft
Development Environment

3
 Click on New Project button on the start page to open New Project Dialog Box

 Select Visual Basic Projects in the Project Types tree list and ASP.Net web service in the
Templates list box in the New Project Dialog box. Then give the location of the web
service to be created in the Location field. By default the location field points to local
host for the service to be created i.e., http://localhost/servicename where servicename
the virtual directory where service has to be created

4
 Click on OK button to create a new solution that includes all files required to develop a
web service.

 Right Click service1.asmx file and select view code from context menu to write the code
for operations in the code window

5
 To write a single function(web service operation), prefix the function name with the
<webmethod()>

 Now write code for 4 functions that accepts 2 numbers as input and does the addition,
subtraction, multiplication and division respectively. Below is the code for respective
functions

<WebMethod()> Public Function Add(ByVal FirstNum As Integer, ByVal SecondNum As Integer) As Integer
Dim out As Integer
out = FirstNum + SecondNum
Return (out)
End Function
<WebMethod()> Public Function Subtract(ByVal FirstNum As Integer, ByVal SecondNum As Integer) As Integer
Dim out As Integer

out = FirstNum - SecondNum


Return (out)
End Function
<WebMethod()> Public Function Multiplication(ByVal FirstNum As Integer, ByVal SecondNum As Integer) As Integer
Dim out As Integer

out = FirstNum * SecondNum


Return (out)
End Function
<WebMethod()> Public Function Division(ByVal FirstNum As Integer, ByVal SecondNum As Integer) As Integer
Dim out As Integer

out = FirstNum / SecondNum


Return (out)
End Function

6
 Now Build the solution by right clicking the solution explorer and selecting Build item
from context menu

 Observe that solution build has been succeeded

 Now execute the solution by pressing F5 and observe that a web page is opened with all
the operations

7
 Now click on Muliplication hyperlink in the opened web page
 A new page opens to accept parameters to perform Multiplication operation

 Provide first and second parameters and click on invoke button .

8
 Observe that a new page is opened with result of multiplication of 2 numbers provided
in the input in the xml format

9
 Now the next part of the web service is to make it consumable by any of the client
application. We'll use the windows application as a client to access the service we
developed

 To develop new windows application, right click the solution in the Solution Explorer and
add new project

10
 When New Project dialog box opens, select Visual Basic Projects in the project types tree
list and windows application in the Templates list box.. Give the name for windows
application(WS_Client) and then click on OK button

11
 Observe that a form is created
 Create 2 text boxes to accept inputs and corresponding labels to describe those text
boxes and 4 buttons to invoke the respective operations of the web service and exit
button to close the application

12
 Now right click the windows application in the Solution explorer and select Add Web
Reference item

 Then Add Web Reference dialog box opens


 Give the url of the service(http://localhost/WS/Service1.asmx) we created in the URL
text box and click on Go icon button . The dialog box shows that a service is found at
the specified location. Alternatively we can click the web services on the local machine
hyperlink which displays all the services on the local host

13
 Now click on Add Reference button and observe that a reference from web service has
been added to the windows application in the solution explorer

14
 Now double click the windows application form to enter code window to write code to
call functions in the web service. When code window opens write the below code

Dim ws As New localhost.Service1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MsgBox(ws.Add(TextBox1.Text, TextBox2.Text))

End Sub

Private Sub WS_Client_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


MsgBox(ws.Subtract(TextBox1.Text, TextBox2.Text))
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click


MsgBox(ws.Multiplication(TextBox1.Text, TextBox2.Text))
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click


MsgBox(ws.Division(TextBox1.Text, TextBox2.Text))
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click


Close()
End Sub

 Now build the windows application and set the windows application as a start up project
by right clicking the windows application and selection set as startup project item

15
 Now execute the solution by pressing F5 and observe windows application opens

 To call web service operation, give the First Number and Second Number in the
available text boxes and click on any of the operation buttons
(Add/Subtract/Multiply/Divide) .

 Then web service operation returns the value which the client application catches and
displays result in the message box

II. Consuming a Free online web service available.

Steps to Consume a free web service available online

 Locate the free web service available online by searching in the google

 Here is one free web service that is available online . This service converts the text from
one language to another language like English to German, English to French.. This web

16
service accepts 2 input parameters, one for language string and another for Language
Mode.

 Now go to Visual Studio and create one windows application to call this freely available
web service

17
 Click on OK button in the New Project dialog box that creates a new windows application

 Design the form to have one combo box that lists all language conversion modes and
one text box to accept the input string and a button to invoke the web service. Also fill
the Language Conversion combo box with the below language conversion modes

EnglishTOChinese
EnglishTOFrench
EnglishTOGerman
EnglishTOItalian
EnglishTOJapanese
EnglishTOKorean
EnglishTOPortuguese
EnglishTOSpanish
EnglishToRussian
EnglishToDutch

18
 Now go to solution explorer, right click windows application and select Add web
reference item from the context menu to add reference to our free web service from
windows application

19
 Now give the URL of free web service in the URL text box available in the Add Web
Reference dialog box and click on Go button

20
 If service is found at the given URL then the page in the dialog box turns below
indicating the service is available

21
 Now click on Add Reference button add web service reference from windows application.
Once the reference has been added, solution explorer will be updated to indicate the
service has been added

22
 Now double click the form in the windows application to open code view and write the
below code to invoke the web service

Dim ws As New net.webservicex.www.TranslateService


Dim i As New Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If ComboBox1.SelectedIndex < 0 Then


MsgBox("Please select language conversion mode")
Else
If ComboBox1.SelectedIndex = 0 Then
i=0
ElseIf ComboBox1.SelectedIndex = 1 Then
i=1
ElseIf ComboBox1.SelectedIndex = 2 Then
i=2
ElseIf ComboBox1.SelectedIndex = 3 Then
i=3
ElseIf ComboBox1.SelectedIndex = 4 Then
i=4
ElseIf ComboBox1.SelectedIndex = 5 Then
i=5
ElseIf ComboBox1.SelectedIndex = 6 Then
i=6
ElseIf ComboBox1.SelectedIndex = 7 Then
i=7
ElseIf ComboBox1.SelectedIndex = 8 Then
i = 29
ElseIf ComboBox1.SelectedIndex = 9 Then
i = 30
End If

MsgBox(ws.Translate(i, Trim(RichTextBox1.Text)))

End If

23
End Sub

 Then save the soluction and execute it by pressing F5

 Once the form is displayed , select the language conversion mode and enter the input
string to be converted

 Then click on the Call Web Service button and observe the response from the web
service in the msgbox

24
III. Case Study on Web Service(SendLoanFile web service)

This StatusMart 3.0 Web Service is designed to provide remote communication between
StatusMart system and client applications such as NexOS, ADVANTedge, Edge etc

This SendLoanFile web method in the SendLoanFile web service is intended for loan
origination systems (such as EDGE, ADVANTedge, and NexOS) to submit loan information to
Status Mart for storage. Successful completion of this web method indicates the loan
information submission request has been queued for processing into Status Mart.
The web method accepts an optional reference ID parameter from the client application.
When the web method completes successfully, a status value “0” is returned. If a reference ID
was not provided, a reference ID will be returned as part of the SendLoanFileResponseEntity
object. The reference ID supplied by the client application or generated by Status Mart can be
utilized by the client application to check the processing status of the request.
When the web method completes with an error condition, a SOAP exception will be returned.
1 SendLoanFile

1.1 Service Call Type


Atlas web service

1.2 Expected Input


Web method signature:
[WebMethod]

[SoapHeader(REQUEST_HEADER, Direction=SoapHeaderDirection.In)]

[SoapHeader(RESPONSE_HEADER, Direction=SoapHeaderDirection.Out)]

public SendLoanFileMessageOut SendLoanFile(SendLoanFileMessageIn sendLoanFileMessageIn)

// some code

Web method Input parameters:

Entry Entry Name Type IsRequired Description


Category
ExecutionPara BizUnit string Mandatory This entry is a string containing business
ms unit code such as CMD, FSL or WLD.
StatusMartEve rqVersion string Optional StatusMart wrapper version.
ntRQ rqVersion=”1”
StatusMartEve rqRevision string Optional StatusMart wrapper revision.
ntRQ rqRevision=”0”
SourceSystem sourceSystemT string Optional Source system name

25
Entry Entry Name Type IsRequired Description
Category
ype
SourceSystem sourceSystemD string Optional Source system date time
tTm
SourceSystem sourceSystemN string Optional Machine that generates XML file
ame
XMLGenerator generatorName string Optional XML Generator module name
XMLGenerator generatorVersi string Optional XML Generator Rel.Ver.BuildNum
on
XMLGenerator generatorMilise string Optional Time in milliseconds that took XML
c Generator to generate XML file
StatusMartEve timeZone string Mandatory Time zone of the source system
ntDetail
StatusMartEve abbreviatedXM string Mandatory Flag to indicate is XML abbreviated.
ntDetail L abbreviatedXML = “N”
StatusMartEve currBrNum string Optional Branch number that sending events to
ntDetail StatusMart
StatusMartEve currBrSatNum string Optional Branch satellite number that sending
ntDetail events to StatusMart
StatusMartEve eventDtTm string Mandatory Event date time
nt
StatusMartEve eventType string Mandatory Event type. Please see Appendix D for all
nt event types
StatusMartEve preappNum string Optional Loan pre-application number
nt
StatusMartEve loanAcctNum string Optional Loan account number
nt
StatusMartEve chlUserNum string Mandatory User number of the user who created
nt event
StatusMartEve EditRights string Optional Flag that indicates if branch that sending
nt events has edit rights on the loan data
LoanFile LoanFile string Mandatory StatusMart subset of loan file XML data.
Please see Appendix A for details.

Atlas SOAP networkUserId string Mandatory Network user id of the caller. It is used
Header for logging and audit purpose.
Atlas SOAP generatorName string Mandatory Name of the program which generated
Header request/response message.
Atlas SOAP generatorVersi string Mandatory Version of the program which generated
Header on request/response message
Atlas SOAP moduleName string Mandatory Module name of the program which
Header generated request/response message

26
Entry Entry Name Type IsRequired Description
Category
Atlas SOAP systemType string Mandatory Details of the source system that owns
Header the request data
Atlas SOAP systemName string Mandatory Details of the source system that owns
Header the request data
Atlas SOAP systemDtTm string Mandatory Details of the source system that owns
Header the request data
Atlas SOAP regionNum string Optional Region number of the service requestor
Header
Atlas SOAP branchNum string Optional Branch number of the service requestor
Header
Atlas SOAP satelliteNum string Optional Satellite number of the service requestor
Header
Atlas SOAP orgUnitNum string Optional OrgUnit number of the service requestor
Header
Atlas SOAP businessSource string Optional Business sources number of the service
Header Num requestor

1.2.1 Input Data Definition


<?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>
<RequestHeader xmlns="http://atlas.countrywide.com">
<SourceSystem sourceSystemType="string" sourceSystemDtTm="string" sourceSystemName="string" />
<MessageGenerator generatorName="string" generatorVersion="string" moduleName="string" />
<OrgUnitInfo regionNum="long" branchNum="long" satelliteNum="long" orgUnitNum="long" businessSourceNum="string" />
<RequestInfo requestId="string" callChainId="string" />
<EnableTrace enable="boolean" />
<LoginName networkUserId="string" />
<EnvironmentCd code="string" />
</RequestHeader>
</soap:Header>
<soap:Body>
<sendLoanFileMessageIn xmlns="http://www.countrywide.com/NexOS">
<SMSendLoanFileExecutionParams bizUnit="string" />
<StatusMartEventRQ rqVersion="string" rqRevision="string">
<SourceSystem sourceSystemType="string" sourceSystemDtTm="string" sourceSystemName="string" />
<XMLGenerator generatorName="string" generatorVersion="string" generatorMilisec="string" />
<StatusMartEventDetail timeZone="string" abbreviatedXML="string" currBrNum="string" currBrSatNum="string">
<StatusMartEventCol>
<StatusMartEvent xsi:nil="true" />
</StatusMartEventCol>
</StatusMartEventDetail>
<Loanfile key="string">
<LoanCol key="string">
<Loan xsi:nil="true" />
</LoanCol>
<CustomerCol key="string">
<Customer xsi:nil="true" />
</CustomerCol>
<PropertyCol key="string">
<Property xsi:nil="true" />
</PropertyCol>
<ApplicationCol key="string">
<Application xsi:nil="true" />
</ApplicationCol>
<CLUESRunCol key="string">
<CLUESRun xsi:nil="true" />
</CLUESRunCol>
<UnderwritingConditionCol key="string">

27
<UnderwritingCondition xsi:nil="true" />
</UnderwritingConditionCol>
</Loanfile>
</StatusMartEventRQ>
</sendLoanFileMessageIn>
</soap:Body>
</soap:Envelope>

1.3 Processing Logic


SendLoanFile web method accepts loanData as an input parameter and queue’s the data for
later processing by the application.

1.4 Expected Output

1.4.1 Output Data Definition

<?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>
<ResponseHeader xmlns="http://atlas.countrywide.com">
<SourceSystem sourceSystemType="string" sourceSystemDtTm="string" sourceSystemName="string" />
<MessageGenerator generatorName="string" generatorVersion="string" moduleName="string" />
<RequestInfo requestId="string" callChainId="string" />
<TraceInfo>
<Trace Category="string" Timestamp="string">
<Message>string</Message>
</Trace>
<Trace Category="string" Timestamp="string">
<Message>string</Message>
</Trace>
</TraceInfo>
<Status code="int" severity="string" message="string" />
</ResponseHeader>
</soap:Header>
<soap:Body>
<SendLoanFileMessageOut xmlns="http://atlas.countrywide.com/">
<SendLoanFileResult referenceID="string" xmlns="http://www.countrywide.com/NexOS" />
</SendLoanFileMessageOut>
</soap:Body>
</soap:Envelope>

1.4.2 Output Data Description


Web method Output parameters:

Entry Entry Name Type IsRequired Description


Category
Message Out referenceID string Mandatory Unique identifier (GUID) that is used to keep track
of web method execution requests. This identifier
will be stored in SM system for future references.
Client applications can call
CheckLoanProcessingStatus with this identifier to
find the processing status. If unique identifier is not
supplied by the client application, one will be
generated.
Atlas SOAP generatorName string Mandatory Name of the program which generated

28
Entry Entry Name Type IsRequired Description
Category
Header request/response message.
Atlas SOAP generatorVersion string Mandatory Version of the program which generated
Header request/response message
Atlas SOAP moduleName string Mandatory Module name of the program which generated
Header request/response message
Atlas SOAP systemType string Mandatory Details of the source system that owns the request
Header data
Atlas SOAP systemName string Mandatory Details of the source system that owns the request
Header data
Atlas SOAP systemDtTm string Mandatory Details of the source system that owns the request
Header data
Atlas SOAP statusCode int Mandatory Web method will return “0” to the client application
Header to indicate successful execution; “false” or SOAP
exception will indicate failure during web method
execution.

1.5 Exception Processing


Client application will be monitoring web service execution and catch all the Atlas exceptions.

1.6 Exception Output


The Atlas exception mechanism will be used for all exception handling.
1.7 Service Level Agreements
The SLA as defined are as follows:
 Load requirements

NexOS will send the following number of events to Status Mart:

CMD events per day: 370,000


CMD events per hour: 37,000
WLD events per day: 187,000
WLD events per hour: 18,700
FSL events per day: 163,000
FSL events per hour: 16,300

 Scalability requirements
In peak market conditions, NexOS will send the following number of events to Status Mart:

29
CMD events per day: 500,000
CMD events per hour: 50,000
WLD events per day: 314,000
WLD events per hour: 31,400
FSL events per day: 163,000
FSL events per hour: 16,300

The service is designed with 24/7 availability in mind and is targeted towards 99.999%
availability.

The service will also provide 30 minutes Disaster Recovery failover.

1.8 Activity Logging


Logging is done through Atlas services.

1.9 Error Logging


Error logging is done through Atlas services.

1.10 Testing SendLoanFile web service using SOAP Tester tool

The URL of the web service is http://atlasnetqa/StatusMartWS/StatusMartWS.asmx

Below is the page containing all web services provided by StatusMart including SendLoanFile
web service

30
If we want to access WSDL file of all StatusMart web services, then we have to just suffix
?WSDL to the StatusMart web services URL which then becomes
http://atlasnetqa/StatusMartWS/StatusMartWS.asmx?WSDL

Below is the web page of the WSDL file of the Statusmart web services

31
Steps to test SendLoanFile web service

 Below is the screenshot of Soap Tester tool

32
 Observe that it has URL combo box to accept URL of the web service and also Soap
Action combo box to accept the method to be called . It also has text area to provide
input data for the web service(In this case, a loan file xml data appended by SOAP
header, SOAP Envelope and SOAP body)
 Also we have Start Run button to call the SendLoanFile web method.
 When we click Start Run button, SendLoanFile method will be called and location of the
output xml file will be put in the Soap Response Text Area

33
Note : The tool, currently is throwing error related to the location of the output file. So, we will
put the soap output screenshots aftersome time

34

Вам также может понравиться