Loading [MathJax]/jax/input/TeX/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Flex 调用添加了SoapHeader的web service

Flex 调用添加了SoapHeader的web service

作者头像
用户3135539
发布于 2018-09-12 03:38:59
发布于 2018-09-12 03:38:59
5940
举报
文章被收录于专栏:

1.NET中撰写需要使用SoapHeader验证的Web Service

代码1:WebService.cs

using System.Web.Services; using System.Web.Services.Protocols;

[WebService(Namespace = "http://www.microsoft.com/")] //名字空间,注意FLEX中调用的时候要手工填写 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]          public class WebService : System.Web.Services.WebService {

         public WebService () {}

public AuthenticationInfo authenticationInfo;

         [WebMethod] [SoapHeader("authenticationInfo")] //为服务添加SoapHeader          public string HelloWorld() {                   if (authenticationInfo == null)  {                            return "验证信息不能为空."                   }                   else{                            if (Authentication.Check(authenticationInfo.username, authenticationInfo.password))  {                                    return "Hello world!"                            }                            else{                                     return "用户名密码验证失败,你没有权力访问此服务。"                            }                   }          } }

//用户密码验证类 public class Authentication {          public static bool Check(string username, string password) {                  return ((username == "user") && (password == "password"));          }         }

代码2:AuthenticationInfo.cs

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;

/// <summary> /// AuthenticationInfo 的摘要说明 /// </summary> public class AuthenticationInfo:System.Web.Services.Protocols.SoapHeader{          public AuthenticationInfo() { }          public AuthenticationInfo(string username ,string password)         {                   this.username = username;                   this.password = password;          }          public string username;          public string password; }

2 在.NET中调用使用了SoapHeader的Web Service

代码3:Form1.cs

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace WindowsApplication1{          public partial class Form1 : Form{                   public Form1() {                            InitializeComponent();                   }                   private void button1_Click(object sender, EventArgs e){                            localhost.WebService service = new WindowsApplication1.localhost.WebService(); localhost.AuthenticationInfo au = new WindowsApplication1.localhost.AuthenticationInfo();                            au.username = textBox1.Text;                            au.password = textBox2.Text; service.AuthenticationInfoValue = au;                            label3.Text = service.HelloWorld();                   }          } }

3 在Flex调用此Web Service

代码4:SoapHeaderTest.mxml

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontFamily="simsun" fontSize="12"> <mx:Script> <![CDATA[         import mx.rpc.events.FaultEvent;         import mx.rpc.events.ResultEvent; import mx.rpc.soap.SOAPHeader;         private function Invoke():void{ ws.clearHeaders(); //先清理一下 var auinfo:Authentication = new Authentication(txtUser.text,txtPassword.text); //                 ws.addHeader(auinfo); //添加                 ws.HelloWorld(); //调用服务         }         private function wsResult(event:ResultEvent):void{                 lblInformation.text= event.result.toString();         }         private function wsFault(event:FaultEvent):void{                 lblInformation.text= event.message.toString();         } ]]> </mx:Script> <mx:WebService id="ws" wsdl="http://localhost:4443/WebSites/WebService.asmx?WSDL" result="wsResult(event)" fault="wsFault(event)"/> <mx:TextInput id="txtUser" x="98" y="94"/> <mx:TextInput id="txtPassword" x="98" y="124"/> <mx:Label x="29" y="98" text="User:"/> <mx:Label x="29" y="128" text="Password:"/> <mx:Button x="193" y="166" label="Invoke" click="Invoke()"/> <mx:Label x="29" y="213" text="Label" id="lblInformation"/> </mx:Application>

代码5:AuthenticationInfo.as

package{         public class AuthenticationInfo{ //字段名称需和.NET端一致                 public var username:String;                 public var password:String;         } }

代码6:Authentication.as

package{         import mx.rpc.soap.SOAPHeader;

public class Authentication extends SOAPHeader{                 public var username:String;                 public var password:String;                 public function Authentication(user:String,password:String){                         var content:AuthenticationInfo = new AuthenticationInfo();                         content.username = user;                         content.password = password; var qname:QName = new QName("http://www.microsoft.com/","AuthenticationInfo"); super(qname, content);                 }         } }

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2007-02-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Flex与外部的数据通信
第3章讲解了视图状态、Flex页面间的跳转、Flex应用的模态窗体、数据绑定、使用拖放,图表等知识。本章将学习Flex与外部的数据通信。在实际开发过程中,Flex应用的数据往往来自于业务逻辑数据提供的服务器端。虽然Flex是用于开发富客户端界面的强大平台,可以编写业务逻辑,但从架构的角度看,仍然需要将核心的业务逻辑放在Flex程序之外。Flex与外部程序的数据通信主要包括HTTPService. WebService和Remoting 3种方式。
张哥编程
2024/12/17
1490
Flex 自定义事件2
LoginEvent.as package events {     import flash.events.Event;     import datas.UserInfo;     public class LoginEvent extends Event     {         public function LoginEvent(user:UserInfo,type:String){             super(type);             this.user = user;
用户3135539
2018/09/12
5340
Flex 自定义事件2
FluorineFx:认证与授权
对认证与授权没啥概念的新同学,建议先看下 .net中的认证(authentication)与授权(authorization),然后再继续。 Flash/Flex在通过FluorineFx调用.Net
菩提树下的杨过
2018/01/23
1K0
FluorineFx:认证与授权
Flex4中使用WCF
虽然flex跟.net交互的首选是FluorineFx,但是如果在某些特定情况下(比如服务端是现成的,不允许修改,或者服务端开发方不懂FluorineFx为何物),这时webService还是挺有用的。 WebService完全可以用"以BasicHttpBinding方式运行的WCF"代替。经过我的实际测试:对于基本类型(比如int,string,datetime以及它们对应的arrry以list),flex调用时能正确识别并“翻译”成as3中对应的int,String,Date以及Array类型,而复杂
菩提树下的杨过
2018/01/22
8420
Flex4中使用WCF
java+flex富互联网应用
MyEclipes + Tomcat6.0 + Flex Builder3 + BlazeDS,网上自己去下载。
kl博主
2023/11/17
1710
Flex 中调用 WebService
import mx.rpc.events.*; import mx.rpc.AbstractOperation; import mx.rpc.soap.WebService; import mx.rpc.*; import mx.controls.*; private function UserLogin(user:String,pass:String):void{                  var ws:WebService = new WebService();          
用户3135539
2018/09/12
7330
flex3整合java
中文网:http://www.adobe.com/cn/products/air/tools/
py3study
2020/01/07
8220
WebService基于SoapHeader实现安全认证
      本文仅提供通过设置SoapHeader来控制非法用户对WebService的调用,如果是WebService建议使用WSE3.0来保护Web服务,如果使用的是Viaual Studio 2008可以使用WCF,WCF里面提供了更多的服务认证方法。以下提供一种基于SoapHeader的自定义验证方式。
跟着阿笨一起玩NET
2018/09/18
1.4K0
WebService基于SoapHeader实现安全认证
Flex 解析显示.net web service的DataTable返回
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" lay
用户3135539
2018/09/12
7210
基于Spring + CXF框架的Web Service
1、用CXF编写基于Spring的Web service,也是需要分为Server服务器端、Client客户端的。
别先生
2020/12/01
1.2K0
基于Spring + CXF框架的Web Service
AIR平台应用
前面的章节中我们学习了Flex的常用控件,Flex与外部通信 ,Cairmgorm框架的使用。到目前位置,我们所创建的Flex应用都是部署到Web服务器上,通过安装在浏览器中的Flash Player运行。事实上Flex应用程序也可以部署成为桌面应用程序,Flex桌面应用程序运行于AIR平台上,AIR相当于AIR应用程序的虚拟机,在应用程序和用户操作系统之间提供一层接口。AIR是AIR应用程序只需要编写一次就可以跨平台运行。
张哥编程
2024/12/17
2230
如何做好Flex与Java交互「建议收藏」
  当大家尝试使用flex与普通java类通信时,一般用RemoteObject,具体的代码段如下:
全栈程序员站长
2022/09/06
5400
Flex3加载外部数据1
1.加载文本文件中的纯文本: LoadData1.mxml <?xml version="1.0" encoding="utf-8"?> <!--通过Bind绑定,使用了MXML的HTTPServi
py3study
2020/01/08
7320
Flex3加载外部数据1
Pylons 和 Flex 3
"Pylons" 和 "Flex 3" 是两个不同的技术,各自有着不同的背景和应用场景:
华科云商小徐
2024/07/03
1420
使用代码分离构建自定义组件
这样,使用一个script标签来编写as代码,mxml代码和as代码混淆在一起,比较混乱,维护困难,看着也比较乱。
高爽
2022/05/07
5150
Cairngorm开发框架
Cairngorm是由adobe公司推出的一个轻量级的Flex RIA程序开发框架。目的是提高程序的可扩展性、可维护性,其本身并不是一个完整的企业应用,它只是提供了一个开发骨架,Adobe称之为体系。 Cairngorm主要就是对开发Flex应用程序应用了一系列的设计模式,从而使开发出来Flex程序可扩展性,可维护性都大大提高。代价就是异常繁琐的文件书写。往往为了完成一个简单的功能需要修改n个文件。所以小项目不建议使用。
张哥编程
2024/12/17
810
WebService客户端调用的5种常见方式
到此一个简单的webservice服务端项目就搭建完成了,这里我在application.properties文件中把端口改成8081:
科技新语
2024/11/21
6390
WebService客户端调用的5种常见方式
Flex常用组件
本章主要介绍如何使用Flex组件构建界面。Flex组件可分为可见组件和非可见组件。可见组件用于界面的外观设计,非可见组件为辅助应用程序的设计。例如,使用Flex非可见组件来存储数据,为一些多值可见组件提供数据源,如下拉框组件。另外,本章还着重介绍了Flex中最常用的几种组件, 包括复选框(CheckBox)、 下拉框(ComboBox)、列表框(List)、单选框(RadioButton)、输入框(Textln- put)、消息提示框(Alert)、AdvancedDataGrid数据表格组件、Tree组件、MenuBar 菜单导航组件、VideoPlayer视频播放组件等。
张哥编程
2024/12/19
2950
ASP.NET AJAX(10)__Authentication ServiceAuthentication ServiceAuthentication Service属性Authentication
在通常情况下,如果使用AJAX方式调用WebService,则可能被恶意用户利用,造成性能以及安全性的问题,所以我们需要使用一些验证方式来保护WebService,最常见方式就是Forms Authentication,这也是一种用法很简单的方式 一个使用FormsAuthentication保护WebService调用的示例 首先创建一个名为ProtectedService的WebService,代码如下 using System; using System.Collections.Generic; us
小白哥哥
2018/03/07
1.9K0
flash/flex图片幻灯片(小图列表,大图展示)
此效果jquery版的请看此处:http://www.cnblogs.com/liulun/archive/2010/11/07/1871145.html
liulun
2022/05/09
4900
flash/flex图片幻灯片(小图列表,大图展示)
相关推荐
Flex与外部的数据通信
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档