Xamarin.Forms WCF async methods (ServiceModel

boris_dvboris_dv USMember ✭✭

Hi, im currently working on a forms application for both android and ios ... and i need to connected to WCF service (corpo app so there will be more services in future that i need to connect to ) ... the problem is that if i use Connected Services and and create a reference.cs it throws an ServiceModel exception during client init

this throws exception :

public ServiceReference1.CWS GetWsClient(string userName, string password)
    {

        try
        {
            var uri = new Uri(HOST_URI);

            BasicHttpsBinding httpsBinding = new BasicHttpsBinding
            {
              Security =
                {
                     Mode = BasicHttpsSecurityMode.Transport,
                        Transport =
                        {
                            ClientCredentialType = HttpClientCredentialType.Basic
                        }
                }

            };

            var factory = new ChannelFactory<ServiceReference1.CWS>(httpsBinding, new EndpointAddress(uri));

            var defaultCredentials = factory.Endpoint.EndpointBehaviors.OfType<ClientCredentials>().First();
            defaultCredentials.UserName.UserName = userName;
            defaultCredentials.UserName.Password = password;

            var ws = factory.CreateChannel();
            return ws;
        }

this is the function :

System.Threading.Tasks.Task<ServiceReference1.GetPermissionsResponse> GetPermissionsAsync(ServiceReference1.GetPermissionsRequest request);

Operation 'GetPermissionsAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message

I saw that this is actually a bug/issue and will be fixed (i hope so) in future ... is there any workaround ?
I know i can create a WebService reference in android/ios projects and handle it with events ... but people dont recommend it (stackoverflow etc.... )

I need to use these services (many other web/desktop apps use them for authorization) ...

Thanks for answers...

Boris

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @boris_dv

    This is not a Xamarin.Forms issue, but an issue in Mono. I would suggest posting comments/asking for a workaround wherever you found the bug/issue that you mentioned.

    WCF has never been fully supported in Mono and likely won't be in the future. When I have asked the Mono team about this in the past they have said (though there is no official word from Microsoft) that WCF is not really being promoted for new projects anymore even by Microsoft, so there did not seem to be a lot of justification for spending the time to fully implement WCF in Mono.

    Here's an article declaring the death of WCF (not an official MS blog): https://blog.tonysneed.com/2016/01/06/wcf-is-dead-long-live-mvc-6/

    I am going to move this to the Cross Platform with Xamarin forum (best match as there is no Mono forum here).

  • abdoelzamalkawyabdoelzamalkawy EGMember ✭✭✭

    @JGoldberger
    So what you are saying that i can't use wsdl or wcf in xamarin .net standard
    because i am adding connected service and when i try to invoke any method from this reference i have an exception

    "System.InvalidOperationException: Operation 'retrieveUserGroupsAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message."

    Do you know how to solve it
    or any way to use wsdl in xamarin forms .net standard project

    Thanks!

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @abdoelzamalkawy said:
    So what you are saying that i can't use wsdl or wcf in xamarin .net standard

    I never said that. There are limitations though. Please go over this document on WCF implementation in Mono:
    http://www.mono-project.com/docs/web/wcf/

    And go over this guide on consuming a WCF service in a Xamarin Forms application: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/consuming/wcf

  • abdoelzamalkawyabdoelzamalkawy EGMember ✭✭✭

    @JGoldberger
    So i tried to add connected service to my portable project
    and it is added
    but when i try to call any method i got this error

    and this is how i call the method

    what is the wrong thing that i am doing here

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited June 2018

    @abdoelzamalkawy

    I am not certain, but you may be hitting this issue:
    https://github.com/dotnet/wcf/issues/1808

    You may also want to look over the comments by Brendan Zagaeski in this bug report:
    https://bugzilla.xamarin.com/show_bug.cgi?id=51959

    So my best guess is that it is an issue with how the proxy was generated. This is what I believe to be the most relevant information from the above (from https://bugzilla.xamarin.com/show_bug.cgi?id=51959#c2 ):

    Generating a proxy with synchronous and APM style asynchronous methods in Visual Studio 2017 version 15.5

    In case any users come across this change in new project experience, note that it is still possible to generate the old WCF proxies that work with Xamarin:

    Run svcutil.exe [5] on the command line in a developer command prompt to generate the proxy. Include the /async flag on the command line if asynchronous methods are desired.

    In my (admittedly very simple) tests with a template "Visual C# > WCF > WCF Service Application", the various synchronous and asynchronous methods in this kind of proxy all worked fine under in Mono, whether compiled directly into the main executable assembly or compiled into a .NET Standard library referenced by the main assembly.

    [5] https://docs.microsoft.com/dotnet/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe

Sign In or Register to comment.