In this post, I will explain how to use WSDL file to consume web service with example. If you want to know WSDL element then please click below link.
WSDL - Element Description
Follow the below step to use WSDL file.
1) Open up Visual Studio.
2) Create a Project (web project or console app : ClientApp - doesn't matter )
3) Right click on Project and click "Add Service Reference"
2) Create a Project (web project or console app : ClientApp - doesn't matter )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Serialization; | |
using System.ServiceModel; | |
using System.Text; | |
namespace WCFpractice | |
{ public class FirstWCFService : IFirstWCFService | |
{ | |
public string Message() | |
{ | |
return "Hello World, this is my first WCF Service"; | |
} | |
} | |
} |
4) Enter the path and name into the Address to import the WSDL file or to consume web service.
This will generate WCF client for you to use all method available in that file or service.
5) You should find a "FirstWCFServiceClient" class which should have all the methods defined on the WSDL contract.
5) You should find a "FirstWCFServiceClient" class which should have all the methods defined on the WSDL contract.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ClientApp.FirstWCFServiceReference; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace ClientApp.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
FirstWCFServiceClient client = new FirstWCFServiceClient(); | |
public ActionResult Index() | |
{ | |
ViewBag.Message= client.Message(); | |
return View(); | |
} | |
public ActionResult About() | |
{ | |
ViewBag.Message = "Your application description page."; | |
return View(); | |
} | |
public ActionResult Contact() | |
{ | |
ViewBag.Message = "Your contact page."; | |
return View(); | |
} | |
} | |
} |
6) Instantiate the client and call the methods.
7) You are done. That's all.
If you have any questions, post here. Also, provide your valuable suggestions and thoughts in form of comments in the section below.
Thank you !!!
If you have any questions, post here. Also, provide your valuable suggestions and thoughts in form of comments in the section below.
Thank you !!!
No comments:
Post a Comment