簡體   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