Web Service Project
You are to develop:
- A currency converter XML web service
- A web service client requesting the currency converter XML web service
The Currency Converter XML Web Service
- Create an ASP.net project named “WebServiceFall2019” (empty and non-HTTPS)
- Add a New Item: Web Service (ASMX) named CurrencyConvert.asmx
- Add the CurrencyConvert web service:<WebMethod()>
Public Function CurrencyConvert(ByVal strCurrencyType As String, ByVal sngCurrencyIn As Single) As String
Dim sngCurrencyOut As Single
Select Case strCurrencyType
Case “ca”
sngCurrencyOut = CSng(sngCurrencyIn) * 1.1
Case “jp”
sngCurrencyOut = CSng(sngCurrencyIn) * 110
End Select
Return sngCurrencyOut
End Function
- Run the web service in a browser from the Visual Studio
- You will see: http://localhost:xxxxx/CurrencyConvert.asmx
- View the Service Description (WSDL)
- Find the web service name: CurrencyConvert
- Find the two input parameters:
<s:element name=”strCurrencyType” type=”s:string” maxOccurs=”1” minOccurs=”0“/>
<s:element name=”sngCurrencyIn” type=”s:float” maxOccurs=”1” minOccurs=”1“/> - Run the CurrencyConvert web service
- Enter a value in the sngCurrencyIn textbox (“ca” or “jp”)
- Enter a value in the strCurrencyType textbox
- Invoke it and view the returned value in an XML
- Run the web service directly in a browser
- Install IIS with Windows 10
- Go to “Turn Windows features on or off”
- Check “Internet Information Services”
- Check “World Wide Web Service”
- Create an Application in IIS
- Go to “Administrative Tools”
- Run “Internet Information Services (IIS) Manager”
- Right click “Default Web Site”
- Run “Add Application”
- In the Alias box: “WebServiceFall2019”
- In the Physical box: locate the path for WebServiceFall2019 (e.g., C:\inetpub\wwwroot\WebServiceFall2019)
- Click OK
- Install IIS with Windows 10
- Run the Currency Converter XML Web Service in a browser
- In the URL box: enter “localhost/ WebServiceFall2019/CurrencyConvert.asmx”
- Run the CurrencyConvert web service
- Enter a value in the sngCurrencyIn textbox (“ca” or “jp”)
- Enter a value in the strCurrencyType textbox
- Invoke it and view the returned value in an XML
The Web Service Client
- Create an ASP.net project named “WebServiceFall2019Client” (empty and non-HTTPS)
- Create a Web Form named “Default.aspx”
- In the <div> and </div>, add the following web controls:<asp:TextBox ID=”tbCurrencyIn” runat=”server”></asp:TextBox><br />
<asp:DropDownList ID=”ddlCurrencyType” runat=”server”>
<asp:ListItem Selected=”True” Value=”ca”>Can</asp:ListItem>
<asp:ListItem Value=”jp”>JP</asp:ListItem>
</asp:DropDownList><br />
<asp:Button ID=”btnConvert_Click” runat=”server” Text=”Button” /><br />
<asp:Label ID=”lblCurrencyOut” runat=”server” Text=”Label”></asp:Label>
- Add a Web Reference
- In the Solution Explorer window, right click the project name “WebServiceFall2019Client”
- Run “Add” > “Service Reference” > “Advanced” > “Add Web Reference” (on the bottom)
- In the URL box: “http://localhost/WebServiceFall2019B/CurrencyConvert.asmx”
- In Web Reference Name box: “CurrencyConverterWebService”
- Click “Add Reference”
- Create a btnConvert_Click event for the btnConvert_Click
- Imports WebServiceFall2019Client. CurrencyConverterWebService
- Create a proxy object:
Dim objWS As CurrencyConverterWebService.CurrencyConvert = New CurrencyConvert()
- Call the Convert web service:
lblCurrencyOut.Text = objWS.CallCurrencyConvert(ddlCurrencyType.SelectedItem.Value, tbCurrencyIn.Text)
- Run the Default.aspx