我无法在Xamarin中与WCF服务建立连接

我的老同事已经开发了VB.NET中的WPF应用程序。现在,我的上级希望通过实现在Android系统上运行的相同概念来替换当前平台。因此,我决定使用Xamarin Android .NET Standard。

在我询问之前,我一直在寻找一种消耗WCF和错误抛出的方法,但是我仍然陷于同一错误。

我已经在android类上设置了服务引用WCF。根据解决方案,我有2个项目:- MyProject MyProject.Android

================================================ ==========================

WPF

Private Function EstablishConnect() As Boolean
    Try
        Dim context As InstanceContext = New InstanceContext(Me)
        svrobj = New DisplayServicesClient(context,"DisplayTcpBinding")
        Dim endpointAddress As New EndpointAddress(modUtility.ServerEndPointAddress)
        svrobj.Endpoint.Address = endpointAddress
        svrobj.Open()
        SecondDiffFromServer = DateDiff(DateInterval.Second,Now,svrobj.GetDateTime)
        Return True
    Catch ex As Exception
        WriteLog.Log(ex.ToString,True)
        Return False
    End Try
End Function

modUtility.ServerEndPointAddress从INI获取:

  

net.tcp:// localhost:8002 / AppServ / WCFServices / Display

================================================ ==========================

XAMARIN形式

private async Task<bool> EstablishConnectAsync()
{
    try
    {
        InstanceContext context = new InstanceContext(this);
        svrobj = new DisplayServicesClient(DisplayServicesClientBase.EndpointConfiguration.DisplayTcpBinding); //,DisplayServicesClientBase.EndpointConfiguration.DisplayTcpBinding
        EndpointAddress endpointAddress = new EndpointAddress(modUtility.ServerEndPointAddress);
        svrobj.Endpoint.Address = endpointAddress;
        await svrobj.OpenAsync();
        modUtility.SecondDiffFromServer = (int)(DateTime.Now - await svrobj.GetDateTimeAsync()).TotalSeconds;
        return true;
    }
    catch (Exception ex)
    {
        Device.BeginInvokeonMainThread(() =>
        {
            ResultText.Text = "Unable to established connection with endpoint service. Ex-" + ex.Message;
        });
        return false;
    }
}

modUtility.ServerEndPointAddress从设置获取:

  

net.tcp://10.0.2.2:8002 / AppServ / WCFServices / Display

我目前正在模拟器上运行android。

我的代码在对svrobj函数的任何调用上都引发异常。以下是引发的错误:-

  1.   

    通信对象System.ServiceModel.DuplexChannelFactory`1 [AppServ.IDisplayServices]不在创建状态,而是在打开状态。

  2.   

    该方法或操作未实现。

我遗漏了某些东西还是实施了错误的方法?

whitegjhh 回答:我无法在Xamarin中与WCF服务建立连接

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169266.html

大家都在问