c# - Windows Phone 8 CommunicationException 远程服务器返回错误 : NotFound

标签 c# wcf windows-phone-8 windows-phone wcf-data-services

我想问一个让我一直抓狂的问题@_@ 我为 Windows Phone 8 制作了一个应用程序,它从 WCF 服务检索数据。 幸运的是,我的同事为我提供了服务。但是,当我使用该服务时,我收到了此错误。

System.ServiceModel.CommunicationException was unhandled by user code
  HResult=-2146233087
  Message=The remote server returned an error: NotFound.
  Source=System.ServiceModel
  StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at NavFinance.NavFinData.NavcoreNavfinServiceClient.NavcoreNavfinServiceClientChannel.EndGetAll(IAsyncResult result)
       at NavFinance.NavFinData.NavcoreNavfinServiceClient.NavFinance.NavFinData.INavcoreNavfinService.EndGetAll(IAsyncResult result)
       at NavFinance.NavFinData.NavcoreNavfinServiceClient.OnEndGetAll(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: NotFound.
       Source=System.Windows
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Net.WebException
            HResult=-2146233079
            Message=The remote server returned an error: NotFound.
            Source=System.Windows
            StackTrace:
                 at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
                 at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
            InnerException:

到处搜索后,我得到了这篇好文章。 http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580(v=vs.105).aspx

但是,我读了它,但还是不明白。为什么? 因为我的服务是用 C# 类编写的,而不是作为 Web 服务。所以我找不到 IIS 服务。

这是我生成数据的代码。

public PurchaseInvoiceMainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(purchaseInvoice_Loaded);
        }

        private void purchaseInvoice_Loaded(object sender, RoutedEventArgs e)
        {
            NavcoreNavfinServiceClient client = new NavcoreNavfinServiceClient();
            client.GetAllCompleted += new EventHandler<GetAllCompletedEventArgs>(client_getAllPurchaseInvoice);
            client.GetAllAsync("509A7214-D3A9-47E7-9BB4-232E670ED650");
        }

        private void client_getAllPurchaseInvoice(object sender, GetAllCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                purchaseDataList.ItemsSource = e.Result;
            }
        }

而且,这是我的服务,它返回结果。

public System.Collections.ObjectModel.ObservableCollection<NavFinance.NavFinData.vwPurchaseInvoice> EndGetAll(System.IAsyncResult result) {
                object[] _args = new object[0];
                System.Collections.ObjectModel.ObservableCollection<NavFinance.NavFinData.vwPurchaseInvoice> _result = ((System.Collections.ObjectModel.ObservableCollection<NavFinance.NavFinData.vwPurchaseInvoice>)(base.EndInvoke("GetAll", _args, result)));
                return _result;
            }

我在这一行得到了异常。

System.Collections.ObjectModel.ObservableCollection<NavFinance.NavFinData.vwPurchaseInvoice> _result = ((System.Collections.ObjectModel.ObservableCollection<NavFinance.NavFinData.vwPurchaseInvoice>)(base.EndInvoke("GetAll", _args, result)));

我使用了许多我发现的技巧,从增加最大字节大小等开始。 它仍然不起作用。 请有人帮助我。我真的很困惑TT_TT

这是我使用的服务。

http://dev.navcore.com/NavFinWebService/Navcore.Navfin.Service.NavcoreNavfinService.svc

大家的任何回答都会让我思考更多,请给出答案。

问候, 布迪·普拉塞蒂奥

最佳答案

此错误表明您的应用程序无法与该服务通信。您是否在手机/模拟器 Internet Explorer 中尝试服务 URL 以确保该 URL 可以访问?

关于c# - Windows Phone 8 CommunicationException 远程服务器返回错误 : NotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19400490/

相关文章:

WCF 测试客户端错误 : Failed to Invoke the service

.net - 什么样的泄漏会导致 WCF 中的 TimeBoundedCache.ExpirableItem 实例泄漏?

c# - WP8 拍摄 map

c# - 属性取决于另一类的属性

c# - 从 C# 中的 SQL 错误读取图像

c# - C#/.NET Entity Framework 中的动态查询生成器

javascript - 根据下拉点击更改javascript中的数据源?

c# - Windows 8.1 通用应用引用

C# 正则表达式匹配

c# - 等待 Task.Factory.FromAsync(BeginXxx, EndXxx) 后 HttpContext 为空