0

Hi, How to call WCF Service from MVC web api and bind the service model into MVC model? Can you please help ?????

[DataContract]
public class Employee
{
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public int Age { get; set; }
}

This is the employee class

EndpointAddress endpointAddress = new EndpointAddress(ConfigurationManager.AppSettings["ServiceKey"]);
string endpointConfigurationName = "SampleSerVice";
ClassProxy obj = new ClassProxy(endpointConfigurationName, endpointAddress);

var result = obj.GetEmployeeName();

result returns the list of employee, but how to bind this to MVC Model

Ajith. K .P
  • 185
  • 9
  • Take a look here http://stackoverflow.com/questions/13200381/asp-net-mvc-4-application-calling-remote-webapi/13207679#13207679 – peco May 02 '16 at 08:09

1 Answers1

0

First of all you need to create WCF Service.

After that you will had to add the ServiceBase Reference in your project. and then go to the link which is provided by the WCFService. and then Add the Service by giving Proper name. After that you need to add the endpoints of the WCF Service which you can find in the Appconfig in the Project where you have added the ServiceBase Reference. Copy the binding name=" " and End points from the AppConfig and paste it in the Web Config. You can Access the WCF Service and to use the Service You need to create the instance of it and then whatever models or methods you need to access it.

  • Acutully the WCF service calling part is success, now problem is am not able to bind the WCF model to MVC model. How to solve this ? – Ajith. K .P May 02 '16 at 09:44
  • Copy the binding name=" " and End points from the AppConfig and paste it in the Web Config. this way you can bind the WCF Service – Hatim Ranapurwala May 02 '16 at 11:18
  • This way i can only get only one json string right. How to map that model into my mvc model. thats my question ????? – Ajith. K .P May 02 '16 at 11:44