WebService 实现BS环境与BS环境传递参数,根据参数生成txt文档
客户端:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Client.aspx.cs" Inherits="客户端.Client" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<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>
</head>
<body>
<form runat="server" id="from1">
时 间:
<asp:TextBox ID="time" runat="server"></asp:TextBox></br>
地 点:
<asp:TextBox ID="address" runat="server"></asp:TextBox></br>
污染物: <asp:TextBox ID="pollutant" runat="server"></asp:TextBox></br>
投放记录:<asp:TextBox ID="PutonRecord" runat="server"></asp:TextBox></br></br>
<asp:Button ID="btn" runat="server" Text="点击传递参数" OnClick="btn_Click" class="btn02"/>
返回的ID为:<asp:Label ID="Id" runat="server" Text=""></asp:Label>
</form>
</body>
</html>
<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>
客户端后台:
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();
}
服务端 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 服务端
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
//参数:时间 ,地点, 污染物, 投放记录
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");
}
}
//污染记录分开写入到para.txt文档中
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");
}
}
//删除原有res.txt文档
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")
{
//存在
FileStream fs = new FileStream(@"C:\Users\jun\Desktop\WaterTools\WaterTools\res.txt", FileMode.Open);
byte[] buffer = new byte[1024 * 1024 * 5];
//实际读取到的有效字节数
int r = fs.Read(buffer, 0, buffer.Length);
//将字节数组解码成字符串
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;
}
}
}
另外防止调用时间超时 ,只需要在客户端设置sendTimeout="00:05:00"这里是标识5分钟在节点binding中设置就好
服务端需要设置 executionTimeout="300000"在httpRuntime中设置
WebService 实现BS环境与BS环境传递参数,根据参数生成txt文档的更多相关文章
- Laravel(PHP)使用Swagger生成API文档不完全指南 - 基本概念和环境搭建 - 简书
在PHPer中,很多人听说过Swagger,部分人知道Swagger是用来做API文档的,然而只有少数人真正知道怎么正确使用Swagger,因为PHP界和Swagger相关的资料实在是太少了.所以鄙人 ...
- 环境变量PATH、cp命令、mv命令、文档查看cat/more/less/head/tail 各个命令的使用介绍
第2周第2次课(3月27日) 课程内容: 2.10 环境变量PATH2.11 cp命令2.12 mv命令2.13 文档查看cat/more/less/head/tail 2.10 环境变量PATH P ...
- Linux CentOS7 VMware 环境变量PATH、cp命令、mv命令、文档查看cat/more/less/head/tail——笔记
一.环境变量PATH PATH一个字符串变量,当输入命令的时候LINUX会去查找PATH里面记录的路径. 命令在这几个目录里面就不需要敲绝对路径 echo $PATH 例子:把/tmp/ 加到 $PA ...
- WebService生成XML文档时出错。不应是类型XXXX。使用XmlInclude或SoapInclude属性静态指定非已知的类型。
情况是SingleRoom和DoubleRoom是Room类的子类.在WebService中有一个方法是返回Room类. public Room Get(int roomId) { return Ro ...
- JAVA基础学习之命令行方式、配置环境变量、进制的基本转换、排序法、JAVA文档生成等(1)
1.命令行方式 dos命令行,常见的命令: dir:列出当前目录下的文件以及文件夹 md:创建目录 rd:删除目录 cd:进入指定目录 cd..:退回到上一级目录 cd/:退回到根目录 del:删除文 ...
- 从0构建webpack开发环境(三) 开发环境以及 webpack-dev-server 的使用
sourceMap 实际应用开发过程中大部分时间都是处于开发模式中,其中需要频繁的修改代码.调试和打包. 但是打包后的代码多个模块压缩到了一个bundle文件,如果出现警告或者异常很难定位到具体模块和 ...
- uboot环境变量(设置bootargs向linux内核传递正确的参数)
这是我uboot的环境变量设置,在该设置下可以运行initram内核(从内存下载到nandflash再运行),但是运行nfs根文件系统的时候一直出错,各种错误.查看了很多资料后猜想应该是uboot传递 ...
- 如何在Azure环境里做好信息传递可扩展性经验分享
作者 王枫 发布于2014年5月15日 综述 本文介绍建立一个在Azure上使用Azure服务总线, 高吞吐量短信平台的必要步骤.在这篇文章中提出的解决方案是在响应由客户的具体要求,建立一个基于Win ...
- Javascript的二进制数据处理学习 ——nodejs环境和浏览器环境分别分析
以前用JavaScript主要是处理常规的数字.字符串.数组对象等数据,基本没有试过用JavaScript处理二进制数据块,最近的项目中涉及到这方面的东西,就花一段时间学了下这方面的API,在此总结一 ...
随机推荐
- tarjan 算法讲解(转)
转自:https://www.byvoid.com/blog/scc-tarjan/ 網誌 列表 標籤 項目 關於 聯繫 四月142009 作者:byvoid 閱讀: 158882 計算機科學 圖論 ...
- 利用switch case判断是今天的第多少天
static void Main(string[] args) { while (true) { int m1 ...
- SQL经典题
1触发器的作用? 答:触发器是一中特殊的存储过程,主要是通过事件来触发而被执行的.它可以强化约束,来维护数据的完整性和一致性, 可以跟踪数据库内的操作从而不允许未经许可的更新和变化.可以联级运算 ...
- qtcreator 与 opencv
参考: http://blog.csdn.net/skeeee/article/details/10585429
- JDK1.5新特性(二)……Static Import
援引 Static Import - This facility lets you avoid qualifying static members with class names without t ...
- oracle 分区和分区索引
一.个人理解:建表时一般都会指定在一个表空间上,但是可能随着表空间扩大,查询越来越慢,分区表就是将一个表实际存在不同的表空间,oracle存储分为块,断,表空间.新建一个表,会给表分配指定大小的段,段 ...
- bzoj 3926 [Zjoi2015]诸神眷顾的幻想乡(SAM)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3926 [题意] 给定一棵树,每个节点都有相应的颜色,且保证叶子数不超过20,问 ...
- 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程05:技能读表》
5.技能读表 技能读表概述: 技能读表,作为实现技能系统更为快捷的一种方式,被广泛应用到游戏开发中.技能配表,作为桥梁连接着游戏策划者和开发者在技能实现上的关系.在游戏技能开发中,开发者只需要根据策划 ...
- nyoj 282 You are my brother
You are my brother 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Little A gets to know a new friend, Litt ...
- UILabel文本垂直顶部对齐的方法
也不知道为什么UILabel本身没有提供文本垂直顶部对齐的方法,真的有点晕.我们创建一个简单的UILabel来看看: [box type="info"] UILabel *myLa ...