Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How should I consume a WCF service using MVC3
- // example of ws
- public class Service1 : IService1
- {
- public string GetData( int value )
- {
- return string.Format( "You entered: {0}", value );
- }
- public CompositeType GetDataUsingDataContract( CompositeType composite )
- {
- if( composite == null )
- {
- throw new ArgumentNullException( "composite" );
- }
- if( composite.BoolValue )
- {
- composite.StringValue += "Suffix";
- }
- return composite;
- }
- }
- // example of mvc action
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- IService1 service = new Service1();
- service.GetDataUsingDataContract(....)
- ViewBag.Message = "Welcome to ASP.NET MVC!";
- return View();
- }
- }
- public ActionResult Index()
- {
- SettingsModel config = null;
- // Set up a channel factory to use the webHTTPBinding
- using (WebChannelFactory<IChangeService> serviceChannel =
- new WebChannelFactory<IChangeService>(new Uri(baseServiceUrl )))
- {
- IChangeService channel = serviceChannel.CreateChannel();
- config = channel.GetSysConfig();
- }
- ViewBag.Message = "Service Configuration";
- return View(config);
- }
Add Comment
Please, Sign In to add comment