通常我会写一个带有问题的小主题,但不是今天 . 我提前为“很多文字”道歉,但这个问题完全让我筋疲力尽 .
The main task was to create Xamarin.Forms application and organize communication with the database through WCF
Visual Studio 2015专业版,最新更新,Xamarin,最新更新 .
步骤1 .
这个link成了我决定的基础 . 我按照本主题中的说明创建了WCF服务 . 首先 - 没有配置对IIS Express的远程访问 .
添加:使用Windows窗体应用程序测试WCF服务 . 通过测试 .
第2步 .
正如我之前所说 - Xamarin.Forms,而不是Xamarin.Android在那个话题中 . 以下是我创建Xamarin.Forms项目的步骤:
新项目 - 跨平台 - 跨平台应用程序(Xamarin.Forms或Native) - 空白应用程序(UI技术) - Xamarin.Forms,代码共享策略 - PCL(可移植类库)
第3步 .
第一个问题:VS2015中Xamarin.Forms的默认模板包括与WCF不兼容的目标平台 . 这意味着我们在拥有此目标平台时无法向PCL添加服务引用 . 这个问题花了很多时间,我的解决方案是:
-
Delete From NuGet Xamarin.Forms - restart VS - Open PCL Properties - Click Change Target Platforms - Remove Windows Phone and Silverlight - restart VS - Add Xamarin.Forms NuGet - the best one I found
-
Rename packages.config to packages.config.BAK - do the same operation with changing platforms
经过其中一种方式 - “添加服务参考” . 当尝试添加服务引用时,第二种方式导致崩溃VS.
第4步 .
我们可以尝试在Xamarin网站的“蓝色笔记”中添加来自VS的服务参考,或者使用SLsvcUtil.exe生成服务客户端类
My client side:
public MainPage()
{
InitializeComponent();
BasicHttpBinding binding = CreateBasicHttp();
MyServiceClient client = new MyServiceClient(binding, new EndpointAddress("http://localhost:9607/MyService.svc"));
client.DoWorkCompleted += Client_DoWorkCompleted;
client.DoWorkAsync(10);
}
private void Client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
var result = e.Result;
}
private static BasicHttpBinding CreateBasicHttp()
{
BasicHttpBinding binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
return binding;
}
第5步 .
运行服务...运行客户端...等待提升DoWorkComleted ...在e.Result中获取 System.Reflection.TargetInvocationException ...
任何人......请帮帮我 . 这个问题控制着我的生活 . 我无法入睡,我无法进食......我只是想着这个......问题......
Link到我的DropBox获取源代码 .
固定 . 主要问题:仿真器的hocalhost不是主工作站的localhost . 为本地网络创建访问权限解决了我的问题