WebServices 简单安全验证以及调用频率限制
2016-09-29 08:28
369 查看
//服务端代码
//调用端代码
namespace WebServicesTest { /// <summary> /// Security 的摘要说明 /// </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 Security : System.Web.Services.WebService { public SecurityHeader securityKey = new SecurityHeader(); public static DateTime lastTime = new DateTime(2010,1,1); [WebMethod] [SoapHeader("securityKey")] public string HelloWorld(string show) { if (DateTime.Now.Subtract(lastTime).TotalSeconds < 30)//30秒 return "访问频率过高!"; lastTime = DateTime.Now; if (securityKey.SecurityKey.Equals("11223")) { return "Security HelloWorld " + show; } else { return "No permissions."; } } [WebMethod] public string HelloWorld1(string show) { return "Public HelloWorld1 " + show; } } public class SecurityHeader : SoapHeader { public string SecurityKey { get; set; } } }
//调用端代码
static void Main(string[] args) { for (int i = 0; i < 5; i++) { Console.WriteLine("第" + i.ToString() + "次调用。"); SecurityService(); Console.WriteLine("-----------------------------"); System.Threading.Thread.Sleep(10000); } } private static void SecurityService() { SecurityHeader header = new SecurityHeader(); header.SecurityKey = "11223"; SecuritySoapClient client = new SecuritySoapClient(); Console.WriteLine(client.HelloWorld1("HelloWorld1:公用")); Console.WriteLine(client.HelloWorld(header, "HelloWorld:私有")); }
相关文章推荐
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- ASP.NET中启用Windows集成验证,怎样在调用System.DirectoryServices下的组件时传递安全上下文,也就是说当前用户凭据,来实现权限管理
- struts2学习笔记(2)――简单的输入验证以及标签库的运用
- 使用Delphi调用WebServices接口的简单应用实例
- xp sp3 + ie8 支付宝证书 导入出错以及安全验证身份出错 解决办法
- 在ASP.NET Atlas中调用Web Service——创建Mashup调用远端Web Service(基础知识以及简单示例)
- WebService 简单安全验证
- struts2学习笔记(2)——简单的输入验证以及标签库的运用
- 如何拿回被恶意或者不小心删除硬盘所有者权限而导致的文件访问以及修改权限被限制(NTFS格式安全权限问题)
- WCF消息安全模式之自定义用户名密码:Message CustomUserNamePassword wsHttpBinding 使用Windows Services宿主以及客户端免证书验证
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- 安全验证码,简单加减法运算,机器无法识别的验证码
- .Net的混淆属性以及ildasm限制的简单解除方法
- 使用Delphi调用WebServices接口的简单应用实例
- 【转载】用const修饰函数 以及引起的附加限制:const函数不能调用非const的函数或引用非const参数
- VB6.0调用WebServices的简单示例
- 突破AsctionScrip安全沙箱限制,网页数据调用中转站
- 在ASP.NET Atlas中调用Web Service——创建Mashup调用远端Web Service(基础知识以及简单示例)
- JS调用ATL DLL 以及 去掉ActiveX 控件安全提示
- 电话号码框限制输入以及电话号码合法性验证