简体   繁体   English

如何在Xamarin android上连接(调用)WCF服务?

[英]how to connect(call) wcf service on xamarin android?

i have 2 project on my solution 1 android 2 wcf service application 我在解决方案1 ​​android 2 wcf service application上有2个项目

i created a service to add my data on my database 我创建了一项服务以将数据添加到数据库中

database info: 数据库信息:

sql server 2014 SQL Server 2014

i tested my service on debug and work fine info: 我在调试中测试了我的服务并正常工作:

connect via liq 通过liq连接

and , add to my android project by add reference service added successfully i can see my tables , fields and ... when i create an instance of my table on click method of my project android project run success but not affect on my database i point a break point on codes and see data to be add but no affect here is my codes 并且,通过添加参考服务成功添加到我的android项目中,我可以看到我的表,字段和...当我在我的项目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);
        }
    }
}

and my service code to add person 和我的服务代码添加人

 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;
        }
    }

please help! 请帮忙!

You can use local network IP address from your PC if your emulator is on the same network. 如果仿真器在同一网络上,则可以从PC使用本地网络IP地址。 Also check if your VM has networks from Oracle box. 还要检查您的VM是否具有来自Oracle的网络框。 That might create problems 那可能会造成问题

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM