Client:
<%@ page language= "C #" autoeventwireup= "true" codebehind= "Client.aspx.cs" inherits= "client. Client "%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script src= "Script/jquery-1.9.1.js" ></script>
<style type= "Text/css" >
#btn {
Cursor:pointer;
height:32px;
font-size:15px;
}
</style>
<body>
<form runat= "Server" id= "from1" >
Time:
<asp:textbox id= "Time" runat= "Server" ></asp:TextBox></br>
Location:
<asp:textbox id= "Address" runat= "Server" ></asp:TextBox></br>
Contaminants: <asp:textbox id= "pollutant" runat= "Server" ></asp:TextBox></br>
Delivery record: <asp:textbox id= "Putonrecord" runat= "Server" ></asp:TextBox></br></br>
<asp:button id= "BTN" runat= "Server" text= "click Pass Parameters" onclick= "Btn_click" class= "Btn02"/>
The returned ID is: <asp:label id= "id" runat= "server" text= "" ></asp:Label>
</form>
</body>
<script type= "Text/javascript" >
$ (' #PutonRecord '). Ready (function () {
$ (' #PutonRecord '). CSS ("width", "400px"),
$ (' #PutonRecord '). CSS ("height", "20px")
});
$ (' #time '). Ready (function () {
$ (' #time '). CSS ("width", "400px"),
$ (' #time '). CSS ("height", "20px")
});
$ (' #address '). Ready (function () {
$ (' #address '). CSS ("width", "400px"),
$ (' #address '). CSS ("height", "20px")
});
$ (' #pollutant '). Ready (function () {
$ (' #pollutant '). CSS ("width", "400px"),
$ (' #pollutant '). CSS ("height", "20px")
});
</script>
Client backend:
protected void Btn_click (object sender, EventArgs e)
{
Servicereference1.webservice1soapclient C = new servicereference1.webservice1soapclient ();
String times = time. Text;
String addr = Address. Text;
String pollu = pollutant. Text;
string putrecord = Putonrecord.text;
int id = C.getdata (times, addr, pollu, Putrecord);
Id.text = ID. ToString ();
}
Service-Side WebService
Using Common;
Using System;
Using System.Collections.Generic;
Using System.Data.SqlClient;
Using System.Diagnostics;
Using System.IO;
Using System.Linq;
Using System.Text;
Using System.Threading;
Using System.Web;
Using System.Web.Services;
Namespace Service side
{
<summary>
Summary description of WebService1
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[System.ComponentModel.ToolboxItem (False)]
To allow this Web service to be called from a script using ASP. NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1:System.Web.Services.WebService
{
Parameters: Time, place, pollutant, delivery record
int id;
[WebMethod]
public int GetData (string time, string address, string pollutant, string Putonrecord)
{
if (time! = NULL && address! = NULL && pollutant! = NULL && Putonrecord! = null)
{
String[] Msgs = {time, address, pollutant};
File.delete (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\para.txt");
for (int i = 0; i < msgs. Length; i++)
{
using (StreamWriter write = new StreamWriter (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\para.txt", True))
{
Write. Write (msgs[i] + "\ r \ n");
}
}
Contamination records are written separately into the Para.txt document
string[] Jilu = Putonrecord.split (");
for (int i = 0; i < Jilu. Length; i++)
{
using (StreamWriter WRI = new StreamWriter (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\para.txt", True))
{
Wri. Write (Jilu[i] + "\ r \ n");
}
}
Delete an existing Res.txt document
Try
{
File.delete (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\res.txt");
}
catch {};
Process.Start (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\WaterTools.exe");
Data ();
}
return ID;
}
public int Data ()
{
Thread.Sleep (31000);
DirectoryInfo di = new DirectoryInfo (@ "C:\Users\jun\Desktop\WaterTools\WaterTools");
filesysteminfo[] infos = di. Getfilesysteminfos ();
for (int i = 0; i < infos. Length; i++)
{
if (Infos[i]. Name = = "Res.txt")
{
Exist
FileStream fs = new FileStream (@ "C:\Users\jun\Desktop\WaterTools\WaterTools\res.txt", FileMode.Open);
byte[] buffer = new BYTE[1024 * 1024 * 5];
The number of valid bytes actually read
int r = fs. Read (buffer, 0, buffer. Length);
Decodes a byte array into a string
String str = Encoding.Default.GetString (buffer, 0, R);
Fs. Close ();
Fs. Dispose ();
String sql = "INSERT into Data (Result) VALUES (@Res) SELECT @ @IDENTITY";
Sqlparameter[] PS = new sqlparameter[] {new SqlParameter ("@Res", str)};
Object obj = sqlhelper.excutescalar (sql, PS);
String o = obj. ToString ();
id = Convert.ToInt32 (o);
Break
}
}
return ID;
}
}
}
In addition to prevent the call time timeout, just need to set sendtimeout= "00:05:00" Here is the identity 5 minutes set in the node binding.
Server needs to set executiontimeout= "300000" in httpruntime
WebService implement BS Environment and BS Environment pass parameters, generate TXT document according to parameters