webservis hatası
05.06.2017 - 06:20
Merhaba arkadaşlar bir web servis hazırladım. Bunu Android de çağırmak istiyorum. Aşağıda oluşturduğum web servis ve android tarafında ki kodları paylaşıyorum. Aldığım hata cannot serialize edittext den gelen veri.
Web Servis
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string UyeGiris(string Eposta, string Sifre)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
String resultJSON = "";
JavaScriptSerializer js = new JavaScriptSerializer();
try
{
Context.Response.Clear();
Context.Response.ContentType = "application/json";
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand();
DataTable dt;
SqlDataReader reader;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spUyeGiris";
cmd.Parameters.AddWithValue("@Email", Eposta);
cmd.Parameters.AddWithValue("@Sifre", Sifre);
cmd.Connection = cn;
reader = cmd.ExecuteReader();
dt = new DataTable("results");
dt.Load(reader);
cn.Close();
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Dictionary<String, Object>> tableRows = new List<Dictionary<string, object>>();
Dictionary<String, Object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col].ToString());
}
tableRows.Add(row);
}
return resultJSON = serializer.Serialize(tableRows).ToString();
}
catch (Exception ex)
{
return resultJSON = ex.Message.ToString();
}
Context.Response.Write(resultJSON);
}
Android
public class Servis {
private static final String METHOD_NAME = "UyeGiris";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/UyeGiris";
private static final String URL = "http://localhost:50672/WebService1.asmx";
SoapObject soapObject;
SoapSerializationEnvelope soapSerializationEnvelope;
HttpTransportSE httpTransport;
public void PushData(Editable eposta, Editable veri) {
soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("Eposta", eposta);
soapObject.addProperty("Sifre", veri);
soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.dotNet = true;
soapSerializationEnvelope.setOutputSoapObject(soapObject);
httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, soapSerializationEnvelope);
SoapPrimitive soapPrimitive=(SoapPrimitive)soapSerializationEnvelope.getResponse();
System.out.println(soapPrimitive.toString());
}
catch (Exception ex) {
ex.printStackTrace();
}
}
338
Görüntülenme
0 Beğeni