[英]Consuming WCF in Xamarin.Forms with App.config
Is is possible to consume WCF service using App.config in Xamarin.Forms? 是否可以使用Xamarin.Forms中的App.config消耗WCF服务? In Xamarin.Forms I have PCL library and three platform projects: iOS, Android and Windows Phone. 在Xamarin.Forms中,我具有PCL库和三个平台项目:iOS,Android和Windows Phone。
Normally (in WPF for example) I have App.config file with such content: 通常(例如,在WPF中)我具有以下内容的App.config文件:
<system.serviceModel>
<client>
<endpoint
address="net.tcp://localhost:8002/FooService"
binding="netTcpBinding"
contract="MyApp.Contracts.IFooService" />
</client>
</system.serviceModel>
GameProxy class, like that: GameProxy类,像这样:
public class GameProxy : ClientBase<IFooService>, IFooService
{
public async Task<BarResponse> BarRequest(int id)
{
return await Channel.BarRequest(id);
}
}
Is is possible to do it in such way in Xamarin.Forms? 是否可以在Xamarin.Forms中以这种方式做到这一点?
There's no App.config file in Xamarin. Xamarin中没有App.config文件。 You simply need to set the values in code like this: 您只需要在如下代码中设置值:
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;
}
The Xamarin documentation has a complete WCF walkthrough . Xamarin文档具有完整的WCF演练 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.