【问题标题】:how to connect(call) wcf service on xamarin android?如何在 xamarin android 上连接(调用)wcf 服务?
【发布时间】:2016-10-23 09:33:27
【问题描述】:

我的解决方案有 2 个项目 1个机器人 2 wcf服务应用程序

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

数据库信息:

sql server 2014

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

通过 liq 连接

并且,通过添加引用添加到我的 android 项目中 服务添加成功 我可以看到我的表格、字段和... 当我在项目的单击方法上创建表的实例时 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;
        }
    }

请帮忙!

【问题讨论】:

  • 我不明白这个问题。您的代码运行正常,但您没有在数据库中看到此人?看来您正在使用实体框架,对吗?调用 GetPerson 时,您是否在服务中遇到断点?
  • @YuriS 不,我在数据库中看到了表,但是当我尝试向数据库中添加一些东西时没有任何反应,
  • 你能在 GetPerson 函数中设置断点吗?你打它吗?如果是,你会在这个函数中遇到异常吗?
  • @YuriS 是的,我放了断点,它没有发送任何功能,只是代码运行而不发生在数据库中
  • 对不起我的英语不好。调用服务时是否命中断点?

标签: c# android wcf xamarin


【解决方案1】:

如果您的模拟器在同一网络上,您可以使用 PC 上的本地网络 IP 地址。还要检查你的虚拟机是否有来自 Oracle 的网络。这可能会产生问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多