windows mobile 访问webservice

webservice:

webservice是一种程序接口,提供数据。可以用java,c#等语言开发。同时调用也可以用多种语言。

即C#可以调用java 写的接口,java也可以调用C#写的接口,总之就是为了分工,安全,方便。

现在使用C#语言调用一个现成的写好的webservice。

步骤:

首先,以本地 webservice为例

项目右键 添加web引用,浏览本地,找到如同http://localhost/EnglishChinese.asmx?wsdl (若是远程接口,只需要更改此URL即可)

找到后 可以查看里面的方法,说明webservice没有问题

然后 记得webservice的 引用名称 自己可以更改的

最后 就是调用里面的方法就可以了。

如果是调用别人的接口,人家会将里面的方法做个说明的,直接调用即可,如下WebReference是引用名,ModuleService是方法。


using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace test001
{
    class Class1
    {

        //函数:调用接口,返回xml数据
        public  String returnData(int ss)
        {

            String data = null;
            String errmsg = null;
            try
            {
                using (WebReference.ModuleService service = new test001.WebReference.ModuleService())
                {
                    service.QuestMessage("DBTS", "", ss, "", "", out data, out errmsg);
                    return data;
                }
            }
            catch
            {
                return null;
            }
            finally {
               if(data!=null) data = null;
               if (errmsg != null) errmsg = null;
                

            }


        }

        //函数:上传数据
        public int uploadData(String data,String id)
        {
            int flag = 0;
            String errmsg = null;
           using (WebReference.ModuleService service = new test001.WebReference.ModuleService())
                {
                    flag=  service.PostMessage("SYGL", "", 0, data, id, out errmsg);
                    return flag;
                    
                }
            
           
          
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值