我的解决方案有2个项目 1个android 2 wcf服务应用
数据库信息:
我在调试时测试了我的服务并正常工作 信息:
并通过添加引用添加到我的android项目中 服务添加成功 我可以看到我的桌子,田地和...... 当我在我的项目的click方法上创建我的表的实例时 android项目运行成功但不影响我的数据库 我在代码上指出一个断点并查看要添加的数据但没有影响 这是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Siman_Android
{
[Activity(Label = "PersonAddActivity")]
public class PersonAddActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Button btn = FindViewById<Button>(Resource.Id.btnadd);
btn.Click += Btn_Click;
}
ServiceRefrence.Service1 myService = new ServiceRefrence.Service1();
private void Btn_Click(object sender, EventArgs e)
{
myService.Url=("http://localhost:13294/Service1.svc");
EditText txtname = FindViewById<EditText>(Resource.Id.txtname);
EditText txtfamily = FindViewById<EditText>(Resource.Id.txtfamily);
myService.GetPersonAsync(txtname.Text, txtfamily.Text);
}
}
}
和我添加人员的服务代码
public bool GetPerson(string FirstName, string LastName)
{
try
{
PersonName pr = new PersonName()
{
Family = LastName,
Name = FirstName
};
db.PersonNames.Add(pr);
db.SaveChanges();
return true;
}
catch (Exception)
{
return false;
}
}
请帮忙!