Application of Windows Services and WebService services in ASP. NET MVC to develop distributed timers
One: Chat:
1. Now the task tracking management system has been developed is almost over, take a little time to write, think of yourself have a sense of accomplishment ah!!
2. Questions about the Windows services encountered in the Task Tracking management system project and the integrated application of WebService.
Hello everybody this is my second time to write a blog, write bad please many understanding, I hope you can make a lot of corrections.
Two: I sort of tidied up a little bit about this distributed timer requirement:
1. The customer number is found in the Answersheet table of the database in the Task Tracking management system (CustomerID is empty), the phone number is not empty record
2. The first case: according to the non-empty telephone number (from the inside of the river system of the database Customer table query data of course in the river system to maintain phone phone number) Call WebService API query customer Customerguid/ CustomerID and returns this string to the task tracking management system if two is not empty call the Answersheetedit () method to update the corresponding task trace management system in Answersheet Customerguid/customerid
3. The second case: according to the non-empty phone number then the WebService API can not query the customer's customerguid/customerid then need to insert Answersheetid and Surveyid in survey table of the river crossing system
and update the Customerguid/customerid data in the Customer table for the river soldier.
4. Every night 23:30 update task tracking management system data and add data to delete the river system
5. The role of the distributed timer is to update the task tracking management system and the users of the river soldiers system and the data of the questionnaire regularly.
Source code for 6.Windows timers
private static readonly Surveyhandle _surveyhandle = new Surveyhandle ();
private static readonly Webserverinterfacehandle _webserverinterfacehandle = new Webserverinterfacehandle ();
Public ServiceTime ()
{
InitializeComponent ();
}
protected override void OnStart (string[] args)
{
Defining timers
Timer MyTimer = new timer (1000);
mytimer.elapsed + = new Elapsedeventhandler (tasktimeaction.servicetime);
Mytimer.enabled = true;
Mytimer.autoreset = true;
using (StreamWriter SW = new StreamWriter ("d:\\ Task Trace Management timer log. txt", true))
{
Sw. WriteLine (DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss") + "timer service start");
}
}
protected override void OnStop ()
{
using (StreamWriter SW = new StreamWriter ("d:\\ Task Trace Management timer log. txt", true))
{
Sw. WriteLine (DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss") + "Stop.");
}
}
<summary>
Method of the Timer delegate task invocation
</summary>
<param name= "source" ></param>
<param name= "E" ></param>
public static void ServiceTime (object source, Elapsedeventargs e)
{
Surveycontroller Surveycontroller = new Surveycontroller ();
if (DateTime.Now.ToString ("HH:mm:ss") = = "23:30:00")
{
Content = DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss" + "23:30 in the Night");
list<answersheet> answersheetlist = _surveyhandle.getanswerguidlist ();
Surveyandanswersheet surveyandanswer = new Surveyandanswersheet ();
foreach (var items in answersheetlist)
{
#region Scheduled synchronization update task tracking management system and the users of the river system and the data of the questionnaire
Answersheet Answersheet = _surveyhandle.getanswersheet (items.id);
Survey Survey = _surveyhandle.getsurvey (Answersheet.surveyid);
Do the detailed content in the query Answerindex
Answersheet answersheetmodel= _surveyhandle.getanswersheetdetail (items.id);
String model = _webserverinterfacehandle.getcustomerjson (items. CustomerID, items. Customerphone);
using (StreamWriter SW = new StreamWriter ("d:\\ Task Tracking Management system timer log. txt", true))
{
Sw. WriteLine (DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss") + "answer number:" + items.id + "customer Number:" + model);
}
if (model = null)
{
string[] Getcustomerid = model. Split (' | ');
string Image = null;
if (answersheet.attachlist! = null)
{
foreach (var image in Answersheet.attachlist)
{
Image + = image.imgURL.Split (' | '). Last ();
}
}
Answersheet.customerguid = getcustomerid[0];
Answersheet.customerid = getcustomerid[1];
Surveyandanswer.answersheet = Answersheet;
Surveyandanswer.survey = Survey;
Surveycontroller.answersheetedit (Surveyandanswer, "/uploads/" + Image);
}
#endregion
}
using (StreamWriter SW = new StreamWriter ("d:\\ Task Tracking Management system timer log. txt", true))
{
Sw. WriteLine (DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss") + ":" + "End Time");
}
}
}
Private Selectcusutomer.webusesevrices webservices = new Selectcusutomer.jiechudianusesevrices ();//Real environment
Private Selectcustomer2.webusesevrices _webservices = new Selectcustomer2.jiechudianusesevrices ();//test environment
Three reasons to write Windows services and WebService services
1. Through the final determination of the Product manager and the customer, finally let me add this new function, so I also actively to do.
It took a half-day to complete the timer development and ended up in the Global.asax file of ASP.
2. Next I created a new project WebService API when I wrote this API, the boss let me use WebService instead of wcf!. How good is WCF!! Through another half-day study began to write WebService API service after debugging and finally released to the test server finally no problem.
3. Then the two begin docking by debugging in the task tracking management system There is no problem docking is also successful, the data on both sides of the database is updated.
4. By the end I publish the task tracking management system to IIS 7.0 up to the specified time data no update found the idle time-out through IIS for 1440 minutes and modify the configuration of the application pool to make a day eventually still did not reach both sides of the system of data synchronization,
Finally, the application pool recycles memory resources and checks the Internet for the instability that IIS has.
5. Finally I decided to use the Windows service to develop the timer cause stability and performance are very good.
IV: About creating Windows services and invoking the WebService service
V: By modifying the Windows service below
App. Config: A file connection database string that modifies the configuration of the database.
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<appSettings>
<add key= "ContactPoint" value= "server=;d atabase=tasktrackdata;uid=sa;password=sa;multipleactiveresultsets= True "/>
<add key= "Clientsettingsprovider.serviceuri" value= ""/>
</appSettings>
<startup>
<supportedruntime version= "v4.0" sku= ". netframework,version=v4.5.2 "/>
</startup>
<system.web>
<membership defaultprovider= "Clientauthenticationmembershipprovider" >
<providers>
<add name= "Clientauthenticationmembershipprovider" type= " System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, version= 4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "serviceuri=" "/>
</providers>
</membership>
<rolemanager defaultprovider= "Clientroleprovider" enabled= "true" >
<providers>
<add name= "Clientroleprovider" type= "System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, version=4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "serviceuri=" " cachetimeout= "86400"/>
</providers>
</roleManager>
</system.web>
</configuration>
Six: Install the service through the command
CMD opens as an administrator and executes as you go.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe D:\WindowsService\WindowsService.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe-u D:\WindowsService\WindowsService.exe
Application of Windows Services and WebService services in ASP. NET MVC to develop distributed timers