简体   繁体   English

我快到了…PhoneGap Android连接到WCF服务

[英]I am almost there…PhoneGap Android connect to WCF Service

Firstly I would like to thank all the experts here on stackoverflow, by reading questions asked and looking at example code and reading the answers i have been able to get to this point. 首先,我想感谢这里所有有关stackoverflow的专家,他们通过阅读所提出的问题并查看示例代码并阅读了我到目前为止能够得到的答案。 Thank you once again! 再一次感谢你!

I have been spending hours and hours searching for a solution, I've read through many posts on this issue. 我一直在花费大量时间寻找解决方案,我已经阅读了许多有关此问题的文章。 It's seem this is a issue a lot of others are/has been struggling with.I would highly appreciate any more advise or tips if somebody can assist in this frustrating issue. 看来这是许多其他人一直在努力的问题。如果有人可以协助解决这个令人沮丧的问题,我将不胜感激,如果您有其他建议或提示,我将不胜感激。

All my development are done on my local machine. 我所有的开发都在本地计算机上完成。 (Win 7, Visual Studio 11beta) (Win 7,Visual Studio 11beta)

A WCF Service is hosted in IIS Express on its own port or IIS 7.5 (.Net Framework 4.0) WCF服务托管在IIS Express中自己的端口或IIS 7.5(.Net Framework 4.0)上

Second Web Application with only Html5/jQuery is hosted in IIS Express on a different port. 仅具有Html5 / jQuery的第二个Web应用程序在另一个端口上的IIS Express中托管。

Using Eclipse 3.7.2 with Android SDK 17 also on my local machine. 在本地计算机上也将Eclipse 3.7.2与Android SDK 17一起使用。 Its seem all the software are functioning properly. 看来所有软件都正常运行。 Android Emulator is working, Phonegap/Cordova library is installed, etc. I am using Android 4.0.3 with Cordova 1.6.0 Android模拟器正在运行,已安装Phonegap / Cordova库,等等。我正在将Android 4.0.3与Cordova 1.6.0结合使用

I am asking assistance to find out why my phonegap emulator ajax call won't go through to my WCF REST Service. 我要求协助以找出为什么我的phonegap模拟器ajax调用无法通过我的WCF REST服务的原因。 I don't have a actual android device now to test the program on at this moment therefore I must use the Emulator. 我现在没有实际的android设备来测试程序,因此,我必须使用Emulator。

Some more detail: 一些细节:

I have a WCF REST Service developed in .Net receiving & sending in JSON and JSON-P. 我有一个用.Net开发的WCF REST服务,可以使用JSON和JSON-P接收和发送。

I have tested this with a second web application on a different port to make sure cross domain calls are allowed. 我已经在另一个端口上的另一个Web应用程序中对此进行了测试,以确保允许跨域调用。

I have also used the RESTclient plugin for Firefox and can use it to make JSON and JSON-P calls successfully. 我还使用了Firefox的RESTclient插件,可以使用它成功进行JSON和JSON-P调用。 [ http://restclient.net/ ] So I am sure the WCF Service is working as it should. [ http://restclient.net/ ]因此,我确定WCF服务可以正常工作。 There shouldn't be any cross domain issue. 不应有任何跨域问题。

When I take the Html file with jQuery that I know is working within Visual Studio, to eclipse, copy into phonegap app, I try to make a basic call to my WCF server and I am unable to connect to the server. 当我将知道在Visual Studio中使用的jQuery的HTML文件带入Eclipse并复制到phonegap应用程序时,我尝试对WCF服务器进行基本调用,但无法连接到该服务器。

I have changed the URL from [http://localhost:50425/LoginService.svc/GetData] to [http://10.0.2.2:50425/LoginService.svc/GetData] according to android documentation : [http://developer.android.com/guide/developing/devices/emulator.html#networkaddresses] 根据android文档,我已将URL从[http:// localhost:50425 / LoginService.svc / GetData]更改为[http://10.0.2.2:50425/LoginService.svc/GetData]:[http:// developer .android.com / guide / developing / devices / emulator.html#networkaddresses]

I have created an allow all whitelist with the following setting: 我使用以下设置创建了一个允许所有白名单:

[ access origin="*" ] [access origin =“ *”]

within the cordova.xml file. 在cordova.xml文件中。 See: [http://professionalaspnet.com/archive/2012/05/15/Whitelisting-Domains-in-Cordova-_2800_PhoneGap_2900_-Android.aspx] 参见:[http://professionalaspnet.com/archive/2012/05/15/Whitelisting-Domains-in-Cordova-_2800_PhoneGap_2900_-Android.aspx]

The correct permissions have been set inside the AndroidManifest.xml file according to [http://docs.phonegap.com/en/1.8.1/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android] 根据[http://docs.phonegap.com/zh-CN/1.8.1/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android]在AndroidManifest.xml文件中设置了正确的权限。

When I initiate the call, I use $.ajaxSetup error function to trap network error etc. and display with alert the error message. 发起呼叫时,我使用$ .ajaxSetup错误函数捕获网络错误等,并显示警告消息。 Used console.log() to make sure it passes this function without a error. 使用console.log()来确保它顺利通过了此函数。

When the call actually happens, I receive a "Bad Request - Invalid Host Name. HTTP 400. The request hostname is invalid." 当实际发生呼叫时,我收到“错误请求-无效的主机名。HTTP400。请求的主机名无效。”

If the call would have been successful, I use breakpoints inside Visual Studio to know for certain the call has been made and see the request coming through. 如果调用会成功,我会在Visual Studio中使用断点来确定调用已经确定,并查看请求是否通过。

Is there any other ways to test from emulator if I can access the "external" host? 如果可以访问“外部”主机,还有其他方法可以从模拟器进行测试吗? In this case to make sure emulator actually can find the service? 在这种情况下,要确保模拟器实际上可以找到服务? Is there any tools or other configuration settings that needs to be done? 是否需要任何工具或其他配置设置?

I have even deleted my emulator and created a new one but it still fails to connect to the WCF Service. 我什至删除了我的模拟器并创建了一个新模拟器,但是仍然无法连接到WCF服务。

I would really like this to work, would like to build a complete phonegap application but can't continue if I can't make a call to a web service. 我真的很想这样做,想构建一个完整的phonegap应用程序,但是如果我无法拨打Web服务,就无法继续。

Any advise would be greatly appreciated. 任何建议将不胜感激。

PhoneGap is really just a wrapper for html/css/js webpages with a js library for accessing phone specific functionality, which can be compiled to multiple native mobile platform apps. PhoneGap实际上只是具有js库的html / css / js网页的包装,用于访问电话特定功能,可以将其编译为多个本机移动平台应用程序。

So this is really not a PhoneGap issue... 所以这真的不是PhoneGap问题...

You say you are using JQuery to query your web service, if you can open the html file which fires of the request in your normal browser window, and everything works fine. 您说您正在使用JQuery查询您的Web服务,如果可以在常规浏览器窗口中打开触发请求的html文件,那么一切正常。 The problem is not with the code, but with the Emulator you are using, maybe some miss configurations idk. 问题不在于代码,而在于您使用的仿真器,可能是idk缺少一些配置。

Okay if that still fails, you are most likely pointing to the wrong/no IIS Instance. 好的,如果仍然失败,您很可能指向错误/没有IIS实例。 If you have two IIS Instances running on port 80 idk how that will behave, but i don't think that will work very well, my guess is that one of them will override the other one. 如果您有两个在80端口idk上运行的IIS实例,它将如何运行,但我认为效果不是很好,我想其中一个将覆盖另一个。

So if you are hosing your webservice on IIS 1, but IIS 2 overrides IIS 1, then you will never reach the webservice, and get the error you get. 因此,如果您要在IIS 1上托管Web服务,但IIS 2会覆盖IIS 1,则您将永远无法访问Web服务,并且会收到错误消息。

So when you changed to point to the other IIS Instance, it started working again. 因此,当您更改为指向另一个IIS实例时,它再次开始工作。

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

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