After the establishment of a good service, we can use this service in the MVC project, before using this service, we need to determine its port, only need to right-click on the SS project, set it as the startup project, and then run the SS project, in the browser address bar, you can see the port number of the service, And you can see the services that have been added to them. (The effect of the run can be seen in section 001, and the port in section 001 is 59068.) )
Add a controller NewsController.cs under the Controllers directory of MVC and include an Action in NewsController.cs to display the page where the news is added
Public ActionResult Create () {return View (); }
Add directory News in the views directory, create a new file in news create.cshtml, or directly create a view page directly from the code on the controller, and add it in the create.cshtml view.
Add an action in NewsController.cs, receive the data submitted by the form on the previous page, and note the declaration
[HttpPost], specify to receive post data
[Httppost] public actionresult create (NewsStory Newsstory) { try { var service = new jsonserviceclient ("http://localhost:59068/"); service. Send<submissionresponse> (New submission () { Body = newsStory.Text, headline = newsstory.headline, SubmissionTime = newsstory.date }); } catch (Exception ex) { viewbag.message = ex. message; } &Nbsp; return view (); }
To run the test:
1 Set the SS project as the startup Project, run the project start service,
2 After starting the service, right-click on the MVC project and select "Debug-Start new instance",
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/54/7F/wKioL1SFGaLTjvNoAAPoad3w2T4734.jpg "title=" Start a new instance. png "alt=" wkiol1sfgaltjvnoaapoad3w2t4734.jpg "/>
3 After you start the MVC site, add a news test on the page where you added the news, and after the submission is successful, you can see the new data in the submission table in the database
The 4 submission table is passed through the DB in the Datarepository addsubmission function. Createtable<submission> (); automatically created, no need to manually build this table
Main references: Getting Started with ASP. NET MVC, ServiceStack and Bootstrap
This article is from the "LifeStage" blog, make sure to keep this source http://soaop.blog.51cto.com/6164600/1587471
ServiceStack Project Example 005 using the first service feature (in an MVC project)