Windows Mobile 5 编程体验3

简介:

今天讲一下移动web开发,就将一个小例子,手机号码归属地查询。首先告诉大家一个网站,www.webxml.com.cn。ok,我们新建一个项目,在项目下新建一个web移动窗体,名为Index.aspx。有的VS2008上没有移动web窗体模板,怎么办呢,需要下载模板文件,在这里我帮大家已经提供了。下载下来根据文件夹下的readme.txt文件把文件拷贝到相应的目录即可。ok,我的目录是C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Templates。然后重启VS08就可以了。页面建好以后我们引用webService,先看看网站给我们提供的webService

我们再看看项目中怎么引用。在项目上点击右键选择添加web引用。输入Endpoint。点击前往

我们看见了webservice的两个方法。在点击添加引用,这个web服务就被我们引用到项目中了。

我们编写前台代码如下

 
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %> 
  2.  
  3. <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> 
  4. <html xmlns="http://www.w3.org/1999/xhtml"> 
  5. <body> 
  6.     <mobile:form id="Form1" runat="server"> 
  7.         <mobile:Label ID="labTitle" ForeColor="#000066" Font-Bold="True" Font-Size="Large" 
  8.             Runat="server" Alignment="Center">手机号码归属地查询</mobile:Label> 
  9.        请输入手机号码:  
  10. <mobile:TextBox ID="txtNumber" Runat="server" ForeColor="#cc3300"> 
  11.        </mobile:TextBox> 
  12. <mobile:Command ID="cmd" Runat="server" OnClick="cmd_click">归属地查询</mobile:Command> 
  13.         <mobile:Label ID="labInfo" ForeColor="#000066" Font-Bold="True" Font-Size="Large" 
  14.             Runat="server" Alignment="Center"> 
  15.         </mobile:Label> 
  16.     </mobile:form> 
  17. </body> 
  18. </html> 

再看看后台

 
  1. using System;  
  2. using System.Collections;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Web;  
  7. using System.Web.Mobile;  
  8. using System.Web.SessionState;  
  9. using System.Web.UI;  
  10. using System.Web.UI.MobileControls;  
  11. using System.Web.UI.WebControls;  
  12. using System.Web.UI.HtmlControls;  
  13. using cn.com.webxml.webservice;  
  14. public partial class Index : System.Web.UI.MobileControls.MobilePage  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.  
  19.     }  
  20.  
  21.     protected void cmd_click(object sender, EventArgs e)  
  22.     {  
  23.         MobileCodeWS mobileCodeWs = new MobileCodeWS();  
  24.         labInfo.Text= mobileCodeWs.getMobileCodeInfo(txtNumber.Text,null);  
  25.     }  
  26. }  

我们先瞧瞧人家网站的运行效果

点击调用,结果如下

我们再看看我们的运行效果

 我发布后在手机模拟器中测试了下,报错,记得什么时候遇到过这种错误,却记不起来了,等记起来再解决吧。

 没想到刚泡杯茶的功夫就解决了,原来要启用网站的写入,

我们再看看

这号码是我随便输的,如有雷同,纯属巧合。



本文转自 BruceAndLee 51CTO博客,原文链接:http://blog.51cto.com/leelei/381349,如需转载请自行联系原作者


相关文章
|
5月前
|
消息中间件 C++ Windows
02 MFC - Windows 编程模型
02 MFC - Windows 编程模型
22 0
|
6月前
|
监控 编译器 API
[笔记]Windows核心编程《二十二》注入DLL和拦截API(一)
[笔记]Windows核心编程《二十二》注入DLL和拦截API
143 0
|
6月前
|
人工智能 缓存 Shell
[笔记]Windows核心编程《二十》DLL的高级操作技术(二)
[笔记]Windows核心编程《二十》DLL的高级操作技术(二)
151 0
|
1天前
|
API C++ Windows
windows编程入门_链接错误的配置
windows编程入门_链接错误的配置
6 0
|
2月前
|
Windows
火山中文编程 -- 第一个windows程序
火山中文编程 -- 第一个windows程序
12 0
|
2月前
|
编译器 API Windows
windows编程基础
windows编程基础
13 0
|
2月前
|
Windows
win32编程 -- windows绘图操作
win32编程 -- windows绘图操作
20 0
|
6月前
|
C++ Windows
[笔记]Windows核心编程《番外篇》几种常见的执行命令行方法
[笔记]Windows核心编程《番外篇》几种常见的执行命令行方法
|
3月前
|
网络协议 Linux C语言
005.在Windows下编程让效率起飞
windows开发Linux方式: 先用编辑器编写源代码 然后进入Linux 系统,使用gcc编译器(后面会讲),对源代码进行编译运行。 熟练后推荐使用VS2019 开发Linux C++ 程序 将自己的Ip地址设为静态IP
40 1
|
4月前
|
人工智能 机器人 C#
Windows编程课设(C#)——基于WPF和.net的即时通讯系统(仿微信)
一款参考QQ、微信的即时通讯软件。采用CS结构,客户端基于.Net与WPF开发,服务端使用Java开发。