有什么受支持的方法可以从跨平台Xamarin代码调用asmx Web服务吗? [英] Is there any supported way to call asmx web services from cross-platform Xamarin code?

查看:272
本文介绍了有什么受支持的方法可以从跨平台Xamarin代码调用asmx Web服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们很难弄清楚如何从跨平台Xamarin代码调用asmx Web服务.似乎有四个选择.前两个似乎有缺陷,而其他两个则缺乏信息.

We are having trouble figuring out how to call asmx web services from cross-platform Xamarin code. There seem to be four options. The first two seem flawed, and information is scarce on the other two.

有人可以提供一些建议吗?当然,必须至少有一种受支持的方式从跨平台 Xamarin应用程序调用Web服务.

Can anyone offer some advice? Surely there must be at least one supported way to call web services from cross platform Xamarin apps.

以下是我们到目前为止所知道的选项:

Here are the options we're aware of so far:

  1. 我们尝试了使用WCF 从可移植类库(PCL)进行呼叫.我们得到了一些错误的行为,这归结为以下事实:Xamarin上的WCF是"仅预览". (生成的XML与在其他WCF实现下运行的同一代码所生成的XML不同,并且未被目标服务器接受.)此外,在面向Windows Phone 8.1的PCL配置文件中不支持WCF. (!)
  2. 我们查看了是否可以放弃使用WCF,并使用PCL中的老式" ASMX型代理.关于这是否可能的信息似乎有很多相互矛盾的信息.例如此处写道,不支持在PCL中使用ASMX样式的Web引用,而您必须使用WCF.但是我们已经确定使用WCF可能不是一个好主意(请参阅#1).
  3. 我们是否应该仅基于HttpClient 滚动我们自己的呼叫代码?
  4. 还是应该放弃所有对PCL的使用,而改为使用共享库?
  1. We tried using WCF to make the calls, from a Portable Class Library (PCL). We got some incorrect behaviour, which we put down to the fact that WCF on Xamarin is "preview" only. (The generated XML was different from that produced by the same code running under other WCF implementations, and was not accepted by the target server.) Furthermore, WCF is not supported in PCL profiles that target Windows Phone 8.1. (!)
  2. We looked up whether we could drop the use of WCF, and use "old school" ASMX-type proxies from a PCL. There seems to be an enormous amount of conflicting information on whether this is even possible. For instance here, a Xamarin employee writes that it's not supported to use ASMX-style web references in PCL, and that you have to use WCF. But we've already established that using WCF could be a bad idea (see #1).
  3. Should we just roll our own calling code, based just on HttpClient?
  4. OR should we drop all use of PCLs, and use Shared Libraries instead?

非常感谢您可以分享的任何帮助或经验.

Many thanks for any help or experiences you can share.

推荐答案

这是我的两分钱,我认为您应该选择3或4 ...

here's my two cents, i think you should go with 3 or 4...

3-您应该重写后端,以使其更加友好,使用更轻便的格式(如json),或者使用asp.net Web api,因为似乎您已经具有.net后端,并且在客户端中使用httpclient.

3 - You should rewrite your backend to be more restfull friendly, use lighter formats like json, maybe use asp.net web api since seems you already have a .net backend , and in the client yes use httpclient.

4-使用共享项目,并且WCF支持应该可以正常工作.可以,但是如果您使用Xamarin.Forms,则共享项目和xaml仍然存在一些问题.

4 - Use shared projects, and WCF support should work ok. This would be ok, but if you are using Xamarin.Forms there's still some issues with Shared projects and xaml.

根据很多事情,我个人会选择3 ..

Depending of a lot of things i would personally go with 3 ..

这篇关于有什么受支持的方法可以从跨平台Xamarin代码调用asmx Web服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆