Description:
In this example we explain that how
to call ASMX Web Service in Asp.Net MVC.or how to call consume ASMX web service
from asp.net MVC.we already previously explain that how to call web service in
asp.net but here we demonstrate how to call web service in MVC.
Here in this example we call the “geoipservice”
to get the name of the country based on the IP address. Generally this web
services are used for getting the country name for which IP Address belongs.
To use this web service in your
application first you have to add Service Reference for the http://www.webservicex.net/geoipservice.asmx
in your application.
Controller:
public class EmployeeController
: Controller
{
public ActionResult Index()
{
return
View();
}
[HttpPost]
public ActionResult Index(string
iPAddress)
{
GeoService.GeoIPService service = new GeoService.GeoIPService();
GeoService.GeoIP output =
service.GetGeoIP(iPAddress.Trim());
ViewBag.Country = "Country: " + output.CountryName;
return
View();
}
}
View:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Call (Consume) Web Service (ASMX) in ASP.Net MVC</title>
<style
type="text/css">
body
{
font-family:
Arial;
font-size:
10pt;
}
</style>
</head>
<body>
@using (Html.BeginForm("Index", "Employee",
FormMethod.Post))
{
@Html.TextBox("IPAddress")
<input type="submit" value="Submit"/>
<hr/>
@ViewBag.Country
}
</body>
</html>
0 comments:
Post a Comment