zoukankan      html  css  js  c++  java
  • PDA(Windows Mobile)调用远程WebService

    之前用模拟器测试过调用远程的WebService,发现总是提示“无法连接到远程服务器”的错误,不管是Windows Mobile6.0 还是6.5都是一样,按照网上的办法,改注册表,修改PDA的配置,安装虚拟网卡,我一一试了一遍,
    都没有解决,可能是模拟器需要什么特殊的配置吧,晚一点继续摸索一下,现在先使用真机来测试一下。

    1.首先新建测试的WebService服务,并将其发布在IIS或者服务器上面,我这里做了两个测试,一个是发布到本地IIS里面,一个是发布到服务器上面。

    以下是我建立的两个测试Web服务。

    复制代码
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Services;
    /// <summary>
    ///WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class WebService : System.Web.Services.WebService
    {
        public WebService()
        {
    
            //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }
    
        [WebMethod]
        public string GetString(string Num1,string Num2)
        {
            return (Convert.ToInt32(Num1) + Convert.ToInt32(Num2)).ToString();
        }    
    
    }
    
    
    
    /// <summary>
    ///WebServices 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
    // [System.Web.Script.Services.ScriptService]
    //public class WebServices : System.Web.Services.WebService 
    public class WebServices : DBHelper
    {
    
        public WebServices()
        {
    
            //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }
    
      
    
        [WebMethod(Description = "检查用户是否存在")]
        public bool CheckUserExists(string UserName)
        {
            bool result = false;
            string strSql = "SELECT COUNT(*) FROM SYS_UserInfo WHERE UserName='" + UserName + "'";
    
            int i = Convert.ToInt32(base.GetScalar(strSql).ToString());
            if (i > 0)
            {
                result = true;
            }
            return result;
        }
    }
    复制代码

    这里就省略掉发布的过程了,先说一下新建智能设备程序的步骤:
    1.新建项目--智能设备--智能设备项目--设置项目名称以及解决方案名称--确定

    2.选择目标平台,这里有 Pokcet PC,Windows CE,Windows Mobile 5.0 SDK,Windows Mobile 6.0 SDK。具体的还要看

    PC上面安装了哪些SDK。

    3.选择.Net Compact FrameWork 版本,2.0/3.0等等。

    4.选择项目模板,表示新建的项目是控制台程序还是引用程序或者是类库等等。


    现在要做的就是在程序里面调用了,先将我们的WebService引用到项目中来,
    项目--右键--添加Web引用--输入服务器IP,如果是本地的话直接点击“本地计算机上面的Web服务”--自己给它命名

    并点击“添加引用”按钮,


    操作成功之后可以在Web References里面看到我们的WebService了,

     

    复制代码
    private void button1_Click(object sender, EventArgs e)
            {
                WebReference.WebServices wbs = new PPCWebS.WebReference.WebServices();//服务器上面的WebService
                bool result = wbs.CheckUserExists(this.txtServerValue.Text.Trim());
                if (result)
                {
                    MessageBox.Show("用户:" + this.txtServerValue.Text.Trim() + "存在数据库中");
                }
                else
                {
                    MessageBox.Show("用户:" + this.txtServerValue.Text.Trim() + "不存在数据库中");
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                WebReference2.WebService w = new PPCWebS.WebReference2.WebService();//本地IIS里面的WebService
                string Result = w.GetString(this.txtLocalhost1.Text.Trim(), this.txtLocalhost2.Text.Trim());
                MessageBox.Show(this.txtLocalhost1.Text.Trim() + "+" + this.txtLocalhost2.Text.Trim() + "=" + Result);
            }
    复制代码

     


    小技巧:通过 Windows CE Remote Zoom-in(远程放大)可以捕获到智能设备的屏幕


    开发的环境:IIS V5.1
                 Visual Studio 2008专业版
                    Windows Mobile 6.1 智能设备
                     Windows Mobile 6.0 SDK

  • 相关阅读:
    接口测试总结
    在 github 上获取源码
    推荐一个css帮助手册的版本 同时提供chm和在线
    由csdn开源项目评选中闹出刷票问题想到投票程序的设计
    由一个园友因为上传漏洞导致网站被攻破而得到的教训
    让 SVN (TortoiseSVN)提交时忽略bin和obj目录
    未能进入中断模式,原因如下:源文件“XXXXXX”不属于正在调试的项目。
    未能加载文件或程序集“XXXXX”或它的某一个依赖项。试图加载格式不正确的程序。
    .Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");
    C# Remoting的一个简单例子
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299133.html
Copyright © 2011-2022 走看看