Question

Create a web service in c# called Continent with one web method called GetContinent. This method...

Create a web service in c# called Continent with one web method called GetContinent. This method should take a string parameter called countryName, and should return a string containing the continent that the country is in.

This web service should return hardcoded country and continent data, as follows,

Country: Brazil. Continent: South America.

Country: United States. Continent: North America.

Country: Canada. Continent: North America.

Country: Zambia. Continent: Africa.

Create a web application that calls your web service. The web application should have one web page, with a TextBox where the user types in a country name, a Button used to get the result, and a Label that shows the output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Web service :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
//application namespace
namespace Demo_WebServiceApp
{
/// <summary>
/// Summary description for Continent
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Continent : System.Web.Services.WebService
{
//web method
[WebMethod]
public string GetContinent(string countryName)
{
countryName = countryName.ToLower();//country name in the lower case
string ContinentName = "";//declaring variable to store Continent
//checking country
if(countryName== "brazil")
{
ContinentName = "South America";//set Continent
}
else if (countryName== "united States" || countryName== "Canada")
{
ContinentName = "North America";//set Continent
}
else if (countryName== "zambia")
{
ContinentName = "Africa";//set Continent
}
else
{
//if country if not present
ContinentName = "Invalid country Name";
}

return ContinentName;//return ContinentName
}
}
}

Client Application :

Here a new Web Application in asp.net with C# is created using Visual Studio 2017 with name "Demo_WebServiceApp".This application contains a web page with name "Default.aspx".Below are the details of this web page.

Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Demo_WebServiceApp._default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%-- title for web page --%>
<title>Continent Name</title>
</head>
<body style="height: 26px">
<form id="form1" runat="server">
<div>
Enter Country Name :<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnContinent" runat="server" Text="Get Continent" OnClick="btnContinent_Click" />
<br />
<br />
<asp:Label ID="lblHeader" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

Default.aspx.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//application namespace
namespace Demo_WebServiceApp
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
//Continent button click
protected void btnContinent_Click(object sender, EventArgs e)
{
//creating object of Service
Continent continent = new Continent();
//calling web method and display Continent
lblHeader.Text = continent.GetContinent(txtCountry.Text);
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :Default.aspx

Screen 2 :Screen when valid country is entered

Screen 3 :Screen when invalid country is entered

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Create a web service in c# called Continent with one web method called GetContinent. This method...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Will reward thumbs up 100% if works. thank you Pickling with Python code and Pandas code Do both ...

    Will reward thumbs up 100% if works. thank you Pickling with Python code and Pandas code Do both pickling assignment in one Jupyter Notebook file. Python Pickle steps: Download the CSV file. Load into a Pandas DataFrame. Make the column ‘country’ the index. Print the header. Using Python code, pickle the DataFrame and name the file: PythonPickle. Load back the PythonPickle data into the DataFrame. Print the header. (Note both printed headers should match.) Pandas Pickle steps: Download the CSV...

  • HI, I need help with this question. Please answer in details. The data set is found below for eac...

    HI, I need help with this question. Please answer in details. The data set is found below for each countries sugar consumption. Thanks! Country,Sugar, GDP, Continent Albania,15.3,4556.144342, Europe Argentina, 38.1,13693.70379, South America Armenia, 33.2,3421.704509, Europe Australia, 34.1, 62080.98242, Europe Austria, 37.9,49485.48219, Europe Azerbaijan,13.9,7189.691229, Europe Belarus,31.8,6305.773662, Europe Belgium, 41.4,46463.60378, Europe Bosnia and Herzegovina,13.4,4754.197861, Europe Brazil, 36.5,12576.19559, South America Canada, 31.3,51790.56695, North America Chile, 41.7,14510.9661, South America China, 6.2,5447.309378,Asia Colombia,23.2, 7124.54892, South America Czech Republic, 30.6,20584.92655, Europe Denmark, 38,59911.90466,Europe Egypt, 26.4,2972.583516,Africa Estonia,31.4,16982.30031,...

  • I am trying to create a program called Count.java that contains a single method called compute...

    I am trying to create a program called Count.java that contains a single method called compute with a string parameter called value. The method should count the number of newlines, words (any sequence of characters separated with whitespace), and characters in a given string and return an array of the three integer values. Use a Scanner to count the number of words in a string. The Scanner.next() method returns the next word, ignoring whitespace.

  • Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter...

    Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called uniqueWords. Create an instance method called write that takes a single parameter called outputFile (representing the path to a text file) and writes the words contained in uniqueWords to the file pointed...

  • HI, I need help with answering these questions. Please explain and answer all parts. Data for all...

    HI, I need help with answering these questions. Please explain and answer all parts. Data for all the countries and then the question at the bottom. Sugar Consumption Per Capita.csv Country Albania Argentina Armenia Australia Austria Azerbaijan Belarus Belgium Bosnia and Herzegovina 13.4 4754.197861 Europe Brazil Canada Chile China Colombia Czech Republic Denmark Egypt Estonia Finland France Georgia Germany Ghana Greece Hungary Iceland India Indonesia Iran Sugar GDP Continent 15.3 4556.144342 Europe 38.1 13693.70379 South America 33.2 3421.704509 Europe 34.1...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the...

    In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the last two values in an int variable. Your method should take as a parameter the integer to extract the last two values from. Your method should check to make sure that the int has at least two digits in it. If it does not your method should simply return-1 If it does extract the last two digits return their sum NOTE You are not...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT