iT邦幫忙

0

App無法呼叫Web service

我在公司內部網路試做App撈取資料庫
web service是用wcf放在localhost
用夜神模擬器測試
但是一直出現連線失敗

using Android.App;
using Android.Widget;
using Android.OS;
using Apptest.localwcf;
using System.Net;
using System;

namespace Apptest
{
    [Activity(Label = "Apptest", MainLauncher = true)]
    public class MainActivity : Activity
    {
        AutoCompleteTextView itemnumber, seqnumber, barcode;
        int textcount=0;   
        protected override void OnCreate(Bundle savedInstanceState)
        {
            
            base.OnCreate(savedInstanceState);            
            SetContentView(Resource.Layout.Main);
            itemnumber = FindViewById<AutoCompleteTextView>(Resource.Id.itemnum);
            seqnumber = FindViewById<AutoCompleteTextView>(Resource.Id.seqnum);
            barcode = FindViewById<AutoCompleteTextView>(Resource.Id.barcode);
            TextView showdetail = FindViewById<TextView>(Resource.Id.showdetail);

            Button btnse = FindViewById<Button>(Resource.Id.btnsearch);

            try
            {
                btnse.Click += (sender, e) => {
                
                    string id = itemnumber.Text.Trim();
                    string se = seqnumber.Text.Trim();
                    string bar = barcode.Text.Trim();
                    Service1 wcftest = new Service1();
                    
                    if (id != "" && se == "" && bar == "")
                        showdetail.Text = wcftest.SearchItemId(id);

                    if (se != "" && id == "" && bar == "")
                    {
                        try
                        {
                            showdetail.Text = wcftest.SearchSeqno(se);
                        }
                        catch (Exception ex)
                        {
                            throw  ex;
                        }
                    }

                    if (bar != "" && se == "" && id == "")
                    {
                        showdetail.Text = wcftest.SearchBarcode(bar);
                    }
                
                };
            }
            catch (Exception ex0)
            {
                throw ex0;
            }
        }
    }
}

另一邊的WCF只先需要回傳輸入的值就可以
用加入參考的方式可以成功回傳

但只要發布到IIS
並在APP加入Web參考
https://ithelp.ithome.com.tw/upload/images/20180102/20108061kBrshuBIcC.png
有試著把localhost改為自己的IP或是電腦名稱
App一開始可以執行
但按下按鈕就會出現錯誤
使用try catch但卻抓不到例外
https://ithelp.ithome.com.tw/upload/images/20180102/20108061rOz5uDoxsV.png
01-02 14:31:44.594 E/mono ( 7811): System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused
01-02 14:31:44.594 E/mono ( 7811): at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in <6c708cf596db438ebfc6b7e012659eee>:0
01-02 14:31:44.594 E/mono ( 7811): at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in <6c708cf596db438ebfc6b7e012659eee>:0
01-02 14:31:44.594 E/mono ( 7811): --- End of inner exception stack trace ---

改成IP或電腦名稱則會出現這個錯誤
https://ithelp.ithome.com.tw/upload/images/20180102/20108061TSsZ3zuLTl.png
01-02 15:46:20.194 E/mono ( 9512): System.Web.Services.Protocols.SoapException: 由於 EndpointDispatcher 的 AddressFilter 不符,因此接收者無法處理具有 To '' 的訊息。請檢查傳送者與接收者的 EndpointAddresses 是否一致。
In mgmain JNI_OnLoad

模擬器可以連到內部server
在裡面瀏覽器輸入網址也可以通
https://ithelp.ithome.com.tw/upload/images/20180102/20108061WOOaqVIhMk.png
請問大大們該怎麼解決

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答