近来又要修改了一些基于 WebService 的应用,把 WebService 在 Compact Framework 下的开发也总结一下。这是一个简单的 step by step 的例子,可以作为入门的参考。
先建立两个项目,WebserivceDevice 为 Device 项目,基于 Compact Framwork, WebSerivceForDevice 为 ASP.NET WebService 项目,源代码见文章后面。
发布 WebService
右键项目 WebSerivceForDevice , 点击 Publish.![](https://i-blog.csdnimg.cn/blog_migrate/d24d1b2a79fcdfee8a08cb097aa818cf.png)
图1
建立 Virtual Directory (虚拟目录)
"Computer Management"->"Services and Applications"->"Internet Information Service"->"Web Sites"->"Default Web Site"。右键新建一个叫做"WebServiceForDevice"虚拟目录。![](https://i-blog.csdnimg.cn/blog_migrate/b18bf54a699cba1aa01c4c8500f481e4.png)
图2
指向发布的目录 "C:\Inetpub\wwwroot\WebServiceForDevice"
![](https://i-blog.csdnimg.cn/blog_migrate/b45f7532da2389ab11514349903f4c5a.png)
图3
一直点击 Next 完成虚拟目录的建立。
测试WebService
在IE上打开新建的虚拟目录,测试新建的WebService。![](https://i-blog.csdnimg.cn/blog_migrate/6f242b3015f5f0261236f60704dcca87.png)
图4
返回 Hello World
![](https://i-blog.csdnimg.cn/blog_migrate/87e6cb83ea61feb87cc5134bed5a5dd2.png)
图5
添加 WebService Reference
在Device的项目下增加 WebService Reference![](https://i-blog.csdnimg.cn/blog_migrate/bf4aa657f5c10980952a7312a507b05b.png)
图6
输入刚刚测试过的网址,点击 "Add Reference"
![](https://i-blog.csdnimg.cn/blog_migrate/28b68af96fff689d4cf15befc2d0bbbc.png)
图7
Winform处理
在Device项目的Winform里面加入一个Label和一个Button。
![](https://i-blog.csdnimg.cn/blog_migrate/e8834910b4028ce9ebfdb80d23c195cc.png)
图8
在 Button 的 Click 事件里面加入以下代码
private
void
buttonRequest_Click(
object
sender, EventArgs e)
{
WebserivceDevice.WebReference.Service1 service = new WebserivceDevice.WebReference.Service1();
service.Url = " http://192.168.1.49/WebServiceForDevice/ServiceForDevice.asmx " ; // hardcode here
labelMsg.Text = service.HelloWorld();
}
{
WebserivceDevice.WebReference.Service1 service = new WebserivceDevice.WebReference.Service1();
service.Url = " http://192.168.1.49/WebServiceForDevice/ServiceForDevice.asmx " ; // hardcode here
labelMsg.Text = service.HelloWorld();
}
测试返回 Hello World
一个简单的基于 Compact Framework 的 WebService 应用就完成了。
皓月长空 同学的 WinCE数据通讯之Web Service篇 。可以进一步学习。
运行环境:VS2008+Windows Mobile 6 Professional SDK
本文转自Jake Lin博客园博客,原文链接:,如需转载请自行联系原作者
http://www.cnblogs.com/procoder/archive/2009/06/10/1500104.html