C# 连接android和asp.net soap Web服务时出错
我已经运行了web服务,下面是代码(我只是第一次尝试登录): 我在使用这个指南: 我正在自己的手机上测试它。问题就在这里 字符串URL=“” 在真实设备中运行时,请使用实时ip地址而不是本地主机,如果要签入emulator,请将本地主机替换为10.0.2.2,这是emulator的ip地址C# 连接android和asp.net soap Web服务时出错,c#,android,asp.net,web-services,soap,C#,Android,Asp.net,Web Services,Soap,我已经运行了web服务,下面是代码(我只是第一次尝试登录): 我在使用这个指南: 我正在自己的手机上测试它。问题就在这里 字符串URL=“” 在真实设备中运行时,请使用实时ip地址而不是本地主机,如果要签入emulator,请将本地主机替换为10.0.2.2,这是emulator的ip地址 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Se
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();
}
}
}
}
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());
}