惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
M
MIT News - Artificial intelligence
腾讯CDC
B
Blog RSS Feed
H
Help Net Security
J
Java Code Geeks
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
博客园_首页
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
博客园 - Franky
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 叶小钗
Martin Fowler
Martin Fowler

博客园 - recx

oracle bi publisher error with word 2007 oracle EBS自定义文件夹以及分配 20110105杂记 删除 excel 加密破解 无聊 PowerCenter Designer小结 NXBRE-Execution 让生活更精致舒适的小常识 关于依赖注入(Denpendency Injection)OR 控制反转(IoC = Inversion of Control) 值得收藏的146条经典民间偏方(转) 食品 rman数据库的启动 oracle 创建同义词(synonym) 问题 农村的机会 别人推荐的书 oracle ctl 文件格式(追加数据) 转:天冷了,大家如果有去年的不穿的衣服别扔....寄给需要的人好吗? 偶对观察者模式的理解
android+soap+.net+webservice
recx · 2011-09-23 · via 博客园 - recx

今天下午一直在折腾android通过soap的方式调用.net下面的webservice服务。

代码很简单,可就是调用不起

测试了很多方法,也谷歌和度娘了一大堆网页,都无用,最后国外网站上的一句话帮我解决了:webservice的命名空间最后需要有反斜杠。

贴出我的代码如下:

第一部分,.net framework4.0下面的webservice服务代码

[WebService(Namespace = "http://tmpuri.org/")]
    ///[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    
///[System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    
// [System.Web.Script.Services.ScriptService]
    public class WebServer : System.Web.Services.WebService
    {
        [WebMethod]
        public string CheckAndLogin(string userID, string userPwd)
        {
            string rtn = string.Empty;
            //登录简单验证
            BLL.UsersTable bll_Users = new BLL.UsersTable();
            using (StreamWriter sw = new StreamWriter("d:\\webservice_ch.txt"true))
            {
                sw.WriteLine("userID为:" + userID + ";       userPwd为:" + userPwd);
            }
            DataTable dt = bll_Users.GetList("UserLogin='" + userID + "' and UserPwd='" + userPwd + "'").Tables[0];
            if (dt.Rows.Count < 1)
            {
                rtn = "usernotfound";
            }
            else
            {
                rtn = dt.Rows[0]["UserName"].ToString();
            }
            return rtn;
        }
}

 请注意第一行代码

[WebService(Namespace = "http://tmpuri.org/")],Namespace的后面需要有/

android上java调用代码如下:

private void soapCheck(){
        String nameSpace = "http://tmpuri.org/";
        String methodName = "CheckAndLogin";
        //String url = "http://192.168.50.148/PDA/WebService/WebServer.asmx";
        String url = "http://192.168.1.9/PDA/WebService/WebServer.asmx";
        String soapAction = "http://tmpuri.org/CheckAndLogin";
        
        try{
            String userID = this.txtName.getText().toString();
            String userPwd = this.txtPwd.getText().toString();
            //request
            SoapObject request = new SoapObject(nameSpace, methodName);
            request.addProperty("userID", userID);
            request.addProperty("userPwd", userPwd);
            //envelope
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            //envelope.encodingStyle = 
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            //call
            HttpTransportSE ht = new HttpTransportSE(url);
              ht.call(soapAction, envelope); 
              
              SoapObject result = (SoapObject) envelope.bodyIn;
              String txt = result.toString();          
              
              new AlertDialog.Builder(this).setMessage(result.getProperty("CheckAndLoginResult").toString()).create().show();
              
        }  catch(Exception ex){
            new AlertDialog.Builder(this).setMessage(ex.getMessage()).create().show();
        }
}