WebService还某种程度上有点象COM,.......
解决方案 »
- 请教Devexpress组件中图片缩放的问题
- C#如何修改XML标签内的数据~~~~~~~~~急!!!!!!!!!
- static函数和普通函数的区别
- 难!怎样在C#中屏蔽Alt+F4,Alt+Tab,Ctrl+Alt+Delete键
- 右键打开vdproj文件后.......
- windows服务程序的Installutil.exe安装问题
- 求助:请帮我看看这段代码为什么是死循环,谢谢!
- c# 操作excel选取不连续的单元格问题
- 关于dataGridView中行的问题
- CrystalReport 中如何設置某項不打印出來(TextObject)
- 在web开发中,如果做到这样一个小功能?--
- ado.net中sqlcommand参数的问题
最简单的方法和调用!
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Xml.XPath;namespace Coordinator
{
/// <summary>
/// Summary description for Coordinator.
/// </summary>
[WebService(Namespace="http://www.linkrun.com.cn/QueryWebService/")]
public class Coordinator : System.Web.Services.WebService
{
// private const string configFile = @"d:\MaterialAssembly\SubApplicationConfig.xml";
// private System.Xml.XPath.XPathDocument doc;
private string Popedom="0";
public Coordinator()
{
InitializeComponent();
} #region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion [WebMethod(EnableSession=true)]
public string Authenticate(string usercode, string password)
{
Operator objOpe = new Operator(usercode);
if(objOpe.ConfirmLogin(password)==1)
{
Session["Popedom"] = objOpe.Popedom;
// this.Application["Popedom"] = objOpe.Popedom;
return objOpe.Name;
}
else
{
return "no";
}
}// [WebMethod]
// public AppFunctionality[] GetFunctionalityCatalog(string token)
// {
// doc = new System.Xml.XPath.XPathDocument(configFile);
//
// XPathNavigator nav = ((IXPathNavigable)doc).CreateNavigator();
// XPathNodeIterator iter = nav.Select("SubApplications/SubApplication");
// AppFunctionality[] functionality = new AppFunctionality[iter.Count];
// int i=0;
// while(iter.MoveNext())
// {
// AppFunctionality f = new AppFunctionality();
// XPathNodeIterator iterSubApp = iter.Current.SelectDescendants(XPathNodeType.Element,true);
// while(iterSubApp.MoveNext())
// {
// if(iterSubApp.Current.Name=="Name")
// f.Name = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="MenuText")
// f.MenuText = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="TopLevelMenuText")
// f.TopLevelMenuText = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="ToolbarIconUrl")
// f.ToolbarIconUrl = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="TooltipText")
// f.TooltipText = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="AssemblyUrl")
// f.AssemblyUrl = iterSubApp.Current.Value;
// if(iterSubApp.Current.Name=="TypeName")
// f.TypeName = iterSubApp.Current.Value;
// }
// functionality[i] = f;
// i++;
// }
// return functionality;
// }
/// <summary>
///必须与认证配合使用
/// </summary>
[WebMethod(EnableSession=true)]
public AppFunctionality[] GetFunctionalityCatalog(string token)
{
MenuItem menuItem=new MenuItem();
System.Data.DataSet dsMenuItem=null;
// Popedom = this.Application["Popedom"].ToString().Trim();//用于全局
Popedom = Session["Popedom"].ToString().Trim();//本用户
dsMenuItem=menuItem.Show(Popedom);
AppFunctionality[] functionality = new AppFunctionality[dsMenuItem.Tables[0].Rows.Count];
int i=0;
if(dsMenuItem!=null)
{
foreach (System.Data.DataRow drv in dsMenuItem.Tables[0].Rows)
{
AppFunctionality f = new AppFunctionality();
f.Name = drv["Name"].ToString();
f.MenuText = drv["MenuText"].ToString();
f.TopLevelMenuText = drv["TopLevelMenuText"].ToString();
f.ToolbarIconUrl = drv["ToolbarIconUrl"].ToString();
f.TooltipText = drv["TooltipText"].ToString();
f.AssemblyUrl = drv["AssemblyUrl"].ToString();
f.TypeName = drv["TypeName"].ToString();
functionality[i] = f;
i++;
}
}
return functionality;
}
/// <summary>
/// GetFunctionalityCatalog重载方法
/// </summary>
[WebMethod(MessageName="GetFunctionalityCatalogUID")]
public AppFunctionality[] GetFunctionalityCatalog(string UID,string PWD)
{
MenuItem menuItem=new MenuItem();
System.Data.DataSet dsMenuItem=null;
dsMenuItem=menuItem.Show(UID,PWD);
AppFunctionality[] functionality = new AppFunctionality[dsMenuItem.Tables[0].Rows.Count];
int i=0;
if(dsMenuItem!=null)
{
foreach (System.Data.DataRow drv in dsMenuItem.Tables[0].Rows)
{
AppFunctionality f = new AppFunctionality();
f.Name = drv["Name"].ToString();
f.MenuText = drv["MenuText"].ToString();
f.TopLevelMenuText = drv["TopLevelMenuText"].ToString();
f.ToolbarIconUrl = drv["ToolbarIconUrl"].ToString();
f.TooltipText = drv["TooltipText"].ToString();
f.AssemblyUrl = drv["AssemblyUrl"].ToString();
f.TypeName = drv["TypeName"].ToString();
functionality[i] = f;
i++;
}
}
return functionality;
}
[WebMethod]
public string DBConnect()
{
return Connection.strConnection;
} }
}
一、他可以过防火墙。当然你可以说任何通讯方式都可以过防火墙,不过都没有他简便。
二、成熟的服务器端支持。WebServices的宿主主机是Web服务器,一般来说无论是IIS或者Apache都经过广泛的使用证明是可靠的,这显然好过你自己编写另一个服务器。
三、易于解析。WebServices使用XML格式及标准词汇表,所以它是自解析格式,对于任意WebServices接口都可以容易的进行软件集成。
四、标准化。错误的看法:
一、WebServices与CORBA形成竞争关系。WebServices是无状态连接,我更喜欢用WebServices替换我的socket部分。与CORBA形成竞争的是Remoting和COM+,WebServices并非是一种纯粹的远程代理。
二、WebServices是未来最重要的终结技术。所有WebServices能做到的事情我用电子邮件一样做到,而且是异步通讯,WebServices终结了谁?WebServices只是诸多通讯技术中的一种,在某些应用上占有一些先天的优势,仅此而已。