繁体   English   中英

错误连接android和asp.net soap webservice

[英]Error connection android and asp.net soap webservice

我已经在运行我的Web服务,这就是代码(我只是首先尝试进行登录):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net.Http;
using System.Web.Http;
using MySql.Data.MySqlClient;

namespace WebService1
{
    /// <summary>
    /// Descripción breve de Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Para permitir que se llame a este servicio web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la línea siguiente. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string ConectarBaseDatos()
        {
            try
            {
                using (MySqlCommand cm = new MySqlCommand())
                {

                    string connection = @"Server=localhost; Port=3306; Database=sistemadatosatletasfecovol; 
                                Uid=****; Pwd=*****";
                    MySqlConnection cn = new MySqlConnection(connection);

                    cm.CommandType = System.Data.CommandType.StoredProcedure;
                    cm.CommandText = "ingresarUsuario";
                    cm.Parameters.Add("_email", MySqlDbType.VarChar).Value = "asdafa@gmail.com";
                    cm.Parameters.Add("_password", MySqlDbType.VarChar).Value = "*****";

                    cn.Open();
                    cm.Connection = cn;
                    cm.ExecuteNonQuery();

                    MySqlDataReader cr = cm.ExecuteReader();       
                    cr.Read();
                    string id;
                    id = cr["mensaje"].ToString();
                    cn.Close();
                    return id;
                }
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }

    }
}

它的工作,我实际上可以测试它,这很好,但是当我尝试将其与andorid连接时,我得到了

android java.net.connectexception无法连接到

错误。

这是我的Android代码

String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "ConectarBaseDatos";
String SOAP_ACTION = "http://tempuri.org/ConectarBaseDatos";
String URL = "http://localhost:8080/Service1.asmx";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);


AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

try
{
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapObject response = (SoapObject)envelope.getResponse();
    String result =  response.getProperty(0).toString();
    editText.setText(result);
}
catch(Exception e)
{
    editText.setText(e.toString());
}

我正在使用本指南: http : //seesharpgears.blogspot.in/2010/11/basic-ksoap-android-tutorial.html,并且正在自己的手机上对其进行测试。

问题出在这里String URL =“ http:// localhost:8080 / Service1.asmx ”;

使用实时IP地址而不是localhost在真实设备中运行,如果要签入模拟器,则将localhost替换为10.0.2.2,这是模拟器的IP地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM