在模拟器中使用kSOAP2使用localhost WCF服务(Consuming a localhost WCF service using kSOAP2 in emulator)
我已经把头撞到了这堵墙上了几天,所以任何帮助都非常感激。
首先是一些背景知识。 我是一位经验丰富的WindowsMobile开发人员,因此我是Java,Android甚至WCF的老手。 我已经做了很多关于如何使用kSOAP2在Android中使用WCF应用程序的研究,但无论我做得最好,我能想到的是由于超时而导致Android中的套接字错误。
首先,我在Visual Studio 2008中创建了一个不需要参数的Web服务应用程序,只需使用字符串值进行响应。 Web服务代码如下:
using System; using System.Collections.Generic; using System.Web; using System.Web.Services; namespace Sample { [WebService(Namespace = "http://sample.com/")] public class Service1 : System.Web.Services.WebService { [WebMethod] public string SayHello() { return "Hello, Android. From your friend, WCF"; } } }
对于此Web服务,我没有调整任何其他设置或对Web.config文件进行任何修改。
当我运行该服务时,它会打开我的浏览器并指向以下网址:
http://localhost:61554/Service1.asmx
接下来,我跳入Eclipse并创建了一个简单的Android项目来使用WCF服务。 对于初学者,我更改了AndroidManifest.xml文件并将此语句添加到其中:
<uses-permission android:name="android.permission.INTERNET" />
现在我的Android类的代码应该是繁重的工作:
package com.sample; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import org.ksoap2.*; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.*; public class Sample extends Activity { TextView result; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); result = (TextView)findViewById(R.id.textViewResult); try { SoapObject Request = new SoapObject("http://sample.com/", "SayHello"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(Request); HttpTransportSE androidHttpTransport = new HttpTransportSE("http://192.168.1.72:61554/Service1.asmx"); androidHttpTransport.call("http://192.168.1.72:61554/SayHello", envelope); SoapObject response = (SoapObject)envelope.getResponse(); String resultValue = response.getProperty(0).toString(); result.setText(resultValue); } catch (Exception e) { result.setText(e.getMessage()); } } }
给我错误的代码行是:
androidHttpTransport.call("http://192.168.1.72:61554/SayHello", envelope);
当在模拟器中运行时,代码到达该行,暂停一两分钟,然后进入具有超时异常的catch块。
关于我可能在这里缺少的任何想法? 感谢您的帮助。
I have rammed my head against this wall for a couple of days now so any help is very appreciated.
A bit of background, first. I am a seasoned WindowsMobile developer moving into Android so I am therefore a noob in Java, Android, and even WCF. I have done a lot of research on how to consume WCF apps in Android using kSOAP2 but no matter what I do the best I can come up with is a socket error in Android because of a time out.
First, I created a web service application in Visual Studio 2008 that requires no parameters and simply responds with a string value. The web service code is as follows:
using System; using System.Collections.Generic; using System.Web; using System.Web.Services; namespace Sample { [WebService(Namespace = "http://sample.com/")] public class Service1 : System.Web.Services.WebService { [WebMethod] public string SayHello() { return "Hello, Android. From your friend, WCF"; } } }
For this web service I did not adjust any other settings or make any modifications to the Web.config file.
When I run the service it opens up my browser and points to the following url:
http://localhost:61554/Service1.asmx
Next, I jumped into Eclipse and created a simple Android project to consume the WCF service. For starters I changed the AndroidManifest.xml file and added this statement to it:
<uses-permission android:name="android.permission.INTERNET" />
Now for the code from my Android class that is supposed to do the heavy lifting:
package com.sample; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import org.ksoap2.*; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.*; public class Sample extends Activity { TextView result; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); result = (TextView)findViewById(R.id.textViewResult); try { SoapObject Request = new SoapObject("http://sample.com/", "SayHello"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(Request); HttpTransportSE androidHttpTransport = new HttpTransportSE("http://192.168.1.72:61554/Service1.asmx"); androidHttpTransport.call("http://192.168.1.72:61554/SayHello", envelope); SoapObject response = (SoapObject)envelope.getResponse(); String resultValue = response.getProperty(0).toString(); result.setText(resultValue); } catch (Exception e) { result.setText(e.getMessage()); } } }
The line of code that is giving me the error is:
androidHttpTransport.call("http://192.168.1.72:61554/SayHello", envelope);
When run in the emulator the code gets to that line, pauses for a minute or two, and then falls into the catch block with a time out exception.
Any ideas on what I might be missing here? The help is appreciated.
原文:https://stackoverflow.com/questions/6538055
最满意答案
您可以使用Andlytics执行此操作 ,但免费版本不允许通知(需要支付2.99美元)。 虽然免费的方式确实可以通过一键式方式查看您的统计数据和评级,而无需调用我认为非常有用的Web浏览器/日志记录。
You can do this with Andlytics, but the free version doesn't allow notifications (need to pay $2.99 for that). Though the free one does have a one-touch way to view your stats and ratings without invoking a web browser/logging in which I find pretty useful.
相关问答
更多-
当我从Google Play市场取消发布应用时会发生什么?(What happens when I unpublish an app from the Google Play market? [closed])[2023-07-03]
如果应用程序未发布,则将无法下载,不会显示在店内搜索结果中,并且无法从商店安装。 即使使用应用程序的直接URL,也不会收到来自Google Play的详细信息。 但是,取消发布不会影响现有安装(所以应用程序不会自动从已安装它的任何设备中删除)。 如果现有用户使用旧版本,仍然可以更新。 无论如何,你都无法使用相同的软件包名称来创建另一个应用程序。 编辑 请注意,您取消发布 (并且这意味着什么名字只是说,不仅仅是APK) - 你隐藏所有相关的东西(在Google Play等应用的页面)。 对于最终用户,它看起来 ... -
Google Play(以前称为Android Market)(与许多其他大型网络服务,包括Apples AppStore)在后台通过不同的服务器共享,以处理来自世界各地的大量请求。 发布新应用程序时,需要一些时间才能更新所有服务器副本。 通过发布我自己的应用程序,花了几分钟,直到详细页面在桌面Web浏览器上工作,但超过一个小时,直到可以在我的手机上打开链接。 在Google Play应用中搜索名称几个小时后未找到我的应用。 Google Publish区域需要更长时间才能显示应用下载的统计信息。 能够下载 ...
-
Android电子市场:如何指定新要求的内容分级?(Android Market: How to specify the newly required content ratings?)[2022-02-16]
该电子邮件表示,从11月30日开始这将是强制性的,所以我假设届时我们将能够分配内容评级。 The email stated that it would be mandatory starting on November 30th, so I assume by then we will be able to assign content ratings. -
当有人评论我对GitHub的提交时,如何获得通知?(How can I get notifications when someone comments on my commit on GitHub?)[2023-06-26]
如果您正在“观看”存储库,我想您会收到通知。 或者,您可以单击每个单独提交中的“订阅”按钮,如下面截图的左下角一样。 但我不确定是否有自动订阅的设置仅由您提交。 If you are "Watching" the repository, I think you will get notified. Alternatively, you can click the "Subscribe" button on each individual commit like in the bottom left corn ... -
我想你可以像在MSDN上一样调用MarketplaceDetail Launcher。 I think you can call to the MarketplaceDetail Launcher like MSDN exposes.
-
现在无法直接将它们发送到“评级和评论”。 Google Play不提供此类选项/ API。 您唯一可以做的就是直接访问Google Play中的应用页面。 是的,如果可能的话,这将是一个很大的优势。 It's not possible to send them directly to "Ratings & Reviews" now. Google Play doesn't provide such an option/API. Only thing you can do is direct to the a ...
-
您可以使用Andlytics执行此操作 ,但免费版本不允许通知(需要支付2.99美元)。 虽然免费的方式确实可以通过一键式方式查看您的统计数据和评级,而无需调用我认为非常有用的Web浏览器/日志记录。 You can do this with Andlytics, but the free version doesn't allow notifications (need to pay $2.99 for that). Though the free one does have a one-touch wa ...
-
用于存储用户评论及其评级的数据库设计[关闭](database design to store user comments and their ratings [closed])[2021-05-14]
2张桌子; 评论和回复 table comments: #Comment_id(int)(pk) *Users_id(int)(fk) *Comment_content (varchar(500)) *Comment_rating(int) *Comment_date(date) table replies: #Reply_id(int)(pk) *Comment_id(int)(fk) *Users_id(int)(fk) *Reply_rating(int) *Reply_content(varcha ... -
班级类型 首先,如果您希望输出是连续的,我建议您将class类型更改为numeric 。 否则,我建议将类标签类型保持为nominal (如您现在所有),但将您的评级更改为{1, 2, 3, 4, 5} 。 如果您更改为数字输出(例如,您可以预测4.5星),那么您将需要使用能够使用数字类的分类器。 使用Weka 我建议看看文档 ,了解有关使用Weka的更多信息,可能需要通过一些教程。 例如,双击ARFF文件后,您应该在“ Classify选项卡中完成大部分工作。 选择分类器,然后选择“ Start 。 分类 ...
-
在Django的评论应用中通过电子邮件通知后续评论(Email notifications for follow-up comments in Django's comments app)[2024-04-01]
这不是内置于django评论框架中,因此您必须自己完成。 您可以将Comment模型子类Comment包含一个布尔字段,该字段跟踪评论者是否希望收到该评论的通知,然后包装post_comment视图以检测此设置 - 对于每个新评论,收集所有其他评论该对象并创建一个想要通知的用户列表,然后使用django-notifications或类似实际发送通知。 在前端,您只需要覆盖templates/comments/form.html以包含新字段,这样就足够了。 这是一个太高的级别,无法提供任何代码示例,因此您必须 ...