简体   繁体   English

Android应用程式与WCF通讯

[英]Android app communicating with WCF

I currently have a client/server application which is based on Windows technology (using C# .net). 我目前有一个基于Windows技术(使用C#.net)的客户端/服务器应用程序。 I use WCF with transport and message credentials. 我将WCF与传输和消息凭据一起使用。 (ie SSL with basic username/password message authentication) (即具有基本用户名/密码消息身份验证的SSL)

One of the projects about to come up, is to allow the client side to run on an Android platform (phone or tablet). 即将推出的项目之一是允许客户端在Android平台(手机或平板电脑)上运行。

Are there Android/Java/Linux libraries available to consume a WCF service from within Android code ? 是否有可用的Android / Java / Linux库从Android代码中使用WCF服务?

If not, I guess I'll have to write a wrapper around the services and use an alternative method. 如果没有,我想我将不得不围绕服务编写一个包装器并使用其他方法。

You can also create a JSON binding for your WCF service - that is expose your WCF service as both a WCF service and a JSON service - then use the standard Android webservice method - which is kind of hokey. 您还可以为WCF服务创建JSON绑定-将WCF服务同时作为WCF服务和JSON服务公开-然后使用标准的Android webservice方法-这是一种骗局。 The advantage of this approach is that you don't have to distribute KSoap - and you are writing less code for the android. 这种方法的优点是您不必分发KSoap-您正在为Android编写更少的代码。 JSON is also uses less band width (if that is an issue) JSON也使用较少的带宽(如果有问题)

WCF basically exposes a SOAP service (provided the binding is set up that way). WCF基本上公开了SOAP服务(前提是以此方式设置了绑定)。 A fairly current-looking Android library can be found at http://code.google.com/p/ksoap2-android/ . 您可以在http://code.google.com/p/ksoap2-android/中找到外观漂亮的Android库。

There is some setup you need to do on the WCF side, though. 不过,您需要在WCF端进行一些设置。 First off, do not use Message security. 首先,不要使用消息安全性。 Use Transport security only. 仅使用传输安全性。 Transport allows you to use HTTPS, which is what you are wanting. 传输使您可以使用所需的HTTPS。 Message security in my experience only works between Windows clients, does not allow SSL (it encrypts the message itself so it can go over an unencrypted channel), and seems not to work with other types of clients. 以我的经验,消息安全性仅在Windows客户端之间起作用,不允许SSL(它对消息本身进行加密,因此它可以通过未加密的通道传输),并且似乎不适用于其他类型的客户端。 If I recall, you want to use some variation of BasicHttpBinding rather than WSHttpBinding, but I don't have a project in front of me at the moment to double-check. 如果我还记得的话,您想使用BasicHttpBinding的某种变体而不是WSHttpBinding,但是我眼前没有一个项目可以仔细检查。

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

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