如何在xamarin android上连接(调用)wcf服务?

时间:2016-10-23 09:33:28

标签: c# android wcf xamarin

我的解决方案有2个项目 1个android 2 wcf服务应用

我创建了一个服务来在我的数据库中添加我的数据

数据库信息:

sql server 2014

我在调试时测试了我的服务并正常工作 信息:

通过liq

连接

并通过添加引用添加到我的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;
        }
    }

请帮忙!

1 个答案:

答案 0 :(得分:0)

如果您的仿真器位于同一网络上,则可以使用PC上的本地网络IP地址。还要检查您的VM是否具有Oracle框中的网络。这可能会产生问题

enter image description here

相关问题