是否可以使用Xamarin.Forms中的App.config来使用WCF服务?在Xamarin.Forms中,我有PCL库和三个平台项目:iOS,Android和Windows Phone。
通常(例如在WPF中)我有包含此类内容的App.config文件:
<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost:8002/FooService"
binding="netTcpBinding"
contract="MyApp.Contracts.IFooService" />
</client>
</system.serviceModel>
GameProxy类,就像那样:
public class GameProxy : ClientBase<IFooService>, IFooService
{
public async Task<BarResponse> BarRequest(int id)
{
return await Channel.BarRequest(id);
}
}
是否可以在Xamarin.Forms中以这种方式进行?
答案 0 :(得分:0)
Xamarin中没有App.config文件。您只需要在代码中设置值,如下所示:
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;
}
Xamarin文档有complete WCF walkthrough。