天天看点

windows mobile开发循序渐进(5)移动应用程序与webservice之间的数据交互

windows mobile上的应用程序除了可以与本地的SQL Server CE进行数据交互,还可以与远程的webservice通信,这个过程基本类似于winform的开发,我们可以先建立一个解决方案,包括一个windows mobile的应用程序项目和一个web网站,其中web网站内只需要添加一个webservice服务页面即可,这里按默认的页面,这个服务内部只有一个默认方法Helloworld,当windows mobile应用程序调用此方法时,可以接收到hello,world!

werservice内只有一个简单方法helloworld(); 

<a target="_blank" href="http://blog.51cto.com/attachment/201106/124314699.png"></a>

添加引用后,在默认的Form1上添加一个按钮,用来触发webservice事件,可以在按钮的点击事件添加如下调用代码:

private void button1_Click(object sender, EventArgs e) 

        { 

            localhost.Service ws = new SmartDeviceProject1.localhost.Service(); 

            MessageBox.Show("Message From webservice: "+ws.HelloWorld()); 

        }

这样即可测试了,但是这里有一个问题,就是在搜索资料时发现webcast中的代码,webservice的地址不是:

<a target="_blank" href="http://localhost:4534/WebSite2/WebService.asmx">http://localhost:4534/WebSite2/WebService.asmx</a>

而是:

<a target="_blank" href="http://wengyuli:4534/WebSite2/WebService.asmx">http://wengyuli:4534/WebSite2/WebService.asmx</a>

就是说这个webservice地址的采用的是PC的名称,不是localhost,可是我两个都测试过,但是都调用不成功,请知道的朋友提示一下啊 谢谢。 

解决方法:

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