1:asp.net做的Webservice
1.打开VS2010后,文件-->新建-->项目-->其他项目类型-->Visual?Studio?解决方案-->空白解决方案?就起名为:?Test?
2.建立表现层(UI) 对着解决方案右键--添加---新建项目--Visual C#--ASP.NET Web应用程序 随便起个名字Android 确定 (注意不是Visual C#--Web-ASP.NET Web应用程序)
3.建立业务逻辑层(BLL)
对着解决方案右键--添加---新建项目--Visual C#--选择类库 随便起个名字BLL确定
4.建立数据访问层(DAL) 对着解决方案右键--添加---新建项目--Visual C#--选择类库 随便起个名字DAL 确定
5.建立Model层(Model) 对着解决方案右键--添加---新建项目--Visual C#--选择类库 随便起个名字Model确定
6建立各层关系,对着WEB层(刚刚建立的UI层)右键--添加引用--选择BLL--确定 同样建立其它关系
1) WEB引用 DAL,Model
2)BLL引用 DAL,Model
3)DAL引用Model (以及解决错误时 引用的System.Configuration )
4)Model无引用
再在刚才Web应用程序Android上右键,添加,新建项Visual C#--Web-Web服务,即可产生一个默认的WebService1.asmx文件
-------------------------------------------------------------------
碰到的问题1:新建项目后解决方案不见了
工具---选项----项目和解决方案----勾选“总是显示解决方案”
碰到的问题2:using不了App_Code里面的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BLL;//要先在WebSite1上添加引用,引用BLL
//为什么using不了App_Code里面的类
//右击类文件,选择属性,有个"bulid action"生成操作,把"content"内容改成"Compile"编译.就ok 了
using skyiv;
碰到的问题3:启动IIS发生意外错误 0x8ffe2740。
打开IIS,在默认网站上按右键,点属性,把TCP端口80改成81即可
------------------------------------------------------------------
上asp.net的WebService1.asmx.cs代码
http://192.168.11.211是本机IP地址
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BLL;//要先在WebSite1上添加引用,引用BLL
//为什么using不了App_Code里面的类
//右击类文件,选择属性,有个"bulid action"生成操作,把"content"内容改成"Compile"编译.就ok 了
using skyiv;
namespace Android
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://192.168.11.211:81/")]
[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
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
//必须加[WebMethod],不然运行http://localhost:81/netWebService/WebService1.asmx
//(在IIS里项目上点右键,点浏览)后这个Add方法出不来
//如果端口有冲突,那么80改为81
//打开IIS,在默认网站上按右键,点属性,把TCP端口80改成81即可
//http://localhost:81/netWebService/WebService1.asmx?wsdl
[WebMethod]
public int Add(int a, int b)
{
return(a+b);
}
[WebMethod]
public string login(string username, string password)
{
string result = "登录成功";
string validatePwd = UserManager.GetUserPasswordByUserName(username);
string qm = UserManager.GetnUserIDByUserName(username);
//加密密码
//string inputPwd = CryptogramManager.EncryptPassword(this.txtPassword.Text.Trim());
des d = new des();
string inputPwd = d.EncryStrHex(password);