简体   繁体   中英

Xamarin.Forms Connection to Wcf Service from iOS

Good day, everyone!

I have an issue: I have a WCF service. Also I have a Xamarin.Forms app, that connects to the server. First time i did it using slsvcutil.exe, but the solution seems to be not really suitable, it was built on events, because of that there were a lot of events and the code was hardly readable. When I tried to do it via ChannelFactory , it worked for Android. Right nowthere are no problems with Android, but for iOS it's ot working at all because of CreateChannel() method. I did another class with ChannelBase using these links:

first link , second link ,

and error dissapears. But it just not connecting to my WCF service... Trying to connect for several days, but still nothing... Maybe any chances to do it in another way? Any help would be appreciated.

ps The code for my iOS interface and class:

public class NewClassForConnectionIOS : ClientBase<IAis7MobileIssoSServerCoreXamarin>, IAis7MobileIssoSServerCoreXamarin
    {

        public NewClassForConnectionIOS() : base() { }

        public NewClassForConnectionIOS(Binding binding, EndpointAddress endpointAddress) : base(binding, endpointAddress) { }

        public NewClassForConnectionIOS(string endpoint) : base(endpoint) { }


        public string[] HttpsGetSessionIdForIssoS(string user, string pass)
        {
            return ((NewClassForConnectionChannel)base.Channel).HttpsGetSessionIdForIssoS(user, pass);
        }

        public IAis7MobileIssoSServerCoreXamarin CreateConnection()
        {
            return CreateChannel();
        }

        protected override IAis7MobileIssoSServerCoreXamarin CreateChannel()
        {
            return new NewClassForConnectionChannel(this);
        }

        private class NewClassForConnectionChannel : ChannelBase<IAis7MobileIssoSServerCoreXamarin>, IAis7MobileIssoSServerCoreXamarin
        {
            public NewClassForConnectionChannel(ClientBase<IAis7MobileIssoSServerCoreXamarin> client) : base(client) { }

            public string[] HttpsGetSessionIdForIssoS(string user, string pass)
            {
                return (string[])base.Invoke("HttpsGetSessionIdForIssoS", new object[] { user, pass });
            }

            //public IAsyncResult BeginHttpsGetSessionIdForIssoS(string user, string pass, AsyncCallback callback, object asyncState)
            //{
            //    object[] _args = new object[2];
            //    _args[0] = user;
            //    _args[1] = pass;
            //    return (IAsyncResult)base.BeginInvoke("HttpsGetSessionIdForIssoS", _args, callback, asyncState);
            //}

            //public string[] EndHttpsGetSessionIdForIssoS(IAsyncResult asyncResult)
            //{
            //    object[] _args = new object[0];
            //    return (string[])base.EndInvoke("HttpsGetSessionIdForIssoS", _args, asyncResult);
            //}
        }
    }

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName ="IAis7MobileIssoSServerCoreXamarin")]
    public interface IAis7MobileIssoSServerCoreXamarin
    {
        [System.ServiceModel.OperationContractAttribute(Action = "HttpsGetSessionIdForIssoS", ReplyAction = "http://tempuri.org/IAis7MobileIssoSServerCoreXamarin/HttpsGetSessionIdForIssoSResponse")]
        string[] HttpsGetSessionIdForIssoS(string user, string pass);
    }

If that would be interesting for somebody, I have resolved that issue. As I mentioned, I didn't have a connection from my iOS device to my WCF service. And after days of searching the info, I tried to connect via physical Android device, not an emulator, and it didn't connect too!

So I investigated, that windows turned on my windows defender.... Lame mistake. After disabling that everything works perfect!

If you'll have such a mistake, please, check your connection from remote device! Hope that will help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM