【问题标题】:app.config Xamarin pclapp.config Xamarin pcl
【发布时间】:2016-10-10 06:07:21
【问题描述】:

我需要在 app.config 文件中添加一些标签来实现 dll (xmlsoccer)。 我必须添加类似

的内容
 <system.serviceModel>
    <bindings>
        <basicHttpBinding>

在一个配置节点中,但我不知道它在哪里。 我试图创建一个 app.config 文件并将 DotNetConfig.xsd 设置为方案,但在编译过程中,我有这个错误:

  • 警告:无法为 * 加载端点配置
  • SyStem.InvalidOperationException:必须为此通道工厂配置绑定

谁能帮帮我?

我试着写这个:

` 公共类 MainActivity : FormsApplicationActivity { public static readonly EndpointAddress EndPoint = new EndpointAddress("http://www.xmlsoccer.com/FootballDataDemo.asmx");

    App application;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        global::Xamarin.Forms.Forms.Init(this, bundle);         
        // LoadApplication(new App(binding, EndPoint));
        CreateBasicHttp();
        LoadApplication(application);
    }

    private  void CreateBasicHttp()
    {
        var binding = new BasicHttpBinding()
        {
            Name = "basicHttpBinding",
            MaxReceivedMessageSize = 1000000,
        };
        binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
        {
            MaxArrayLength = 2147483646,
            MaxStringContentLength = 5242880,
        };
        var timeout = new TimeSpan(0, 1, 0);
        binding.SendTimeout = timeout;
        binding.OpenTimeout = timeout;
        binding.ReceiveTimeout = timeout;      
        application = new App(binding, new EndpointAddress("http://www.xmlsoccer.com/FootballDataDemo.asmx"));
    }`

在我的 MainActivity.cs 中,但显然这还不够。

【问题讨论】:

  • Xamarin 移动应用不使用 app.config 文件。
  • 完美 -_- 那么,有什么建议可以解决这个问题吗?
  • 从您发布的内容来看,我不知道您在 app.config 中实际需要做什么。如果它只是可以通过编程方式完成的 WCF 服务的绑定。
  • 我不能在这个范围内使用 AndroidManifest.xml 吗?

标签: binding configuration xamarin.forms app-config


【解决方案1】:

还在寻找答案? 看看这里: https://forums.xamarin.com/discussion/19303/how-to-consume-wcf-service-in-xamarin-forms-pcl

步骤:

1.- 在 Windows 中打开命令提示符并使用 SLSvcUtil.exe 工具 从 Silverlight SDK 从 WSDL 文件生成代理。 slsvcutil http://www.yourserver.com/WebServices/YourServiceSoapClient.asmx?WSDL /out:YourService.cs 该实用程序位于我计算机上的 C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Tools\。

2.- 将生成的 YourService.cs 文件添加到我的项目中。

3.- 添加以下代码访问服务:

   // Create the WCF client (created using SLSvcUtil.exe on Windows)
   YourServiceSoapClient client = new YourServiceSoapClient(
      new BasicHttpBinding(),
      new EndpointAddress("hhttp://www.yourserver.com/WebServices/YourServiceSoapClient.asmx"));

   // Call the proxy - this should use the async versions
   client.ServiceFunctionCompleted += OnGotResult;
   client.ServiceFunctionAsync(parameter);

还有 OnGotResult 函数:

void OnGotResult(object sender, ServiceFunctionCompletedEventArgs e)
{
    Device.BeginInvokeOnMainThread(async () => {
        string error = null;
        if (e.Error != null)
            error = e.Error.Message;
        else if (e.Cancelled)
            error = "Cancelled";

        if (!string.IsNullOrEmpty(error))
        {
            await DisplayAlert("Error", error, "OK", "Cancel");
        }
        else
        {
            resultsLabel.Text = e.Result;
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多