none
Problem with WCF Soap service in mono project ( Xam.Android ) RRS feed

  • Question

  • Hi,

    I'm trying to develop a Xamarin App (Xam 4.7.10.38 with Xam.And.SDK 8.0.2.1 using PCL approach) connected to an Dynamics 365 Finance And Operation Custom Web Service.
    Just to sum it up, it's a WCF Soap service that uses Azure Active Directory Client Id + Client Secret to connect to the soap service.

    I've posted the most important part of the code below for reference.

    So as instructed, I used the Silverlight SDK to create the service reference proxy class and also added the necessary framework references.
    Then I included this proxy class in my Android Project as wel as in a standard .Net Windows App, both using VS.Net 2017.

    Everything is identical up until I call "var resultAsync = service.BeginValidateUser(validateUserRequest, null, null);"

    In my Windows App, it returns System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.
    I do the WaitOne to conclude it and my EndValidateUser returns a correct result.

    However in my Android App, it returns System.Runtime.Remoting.Messaging.AsyncResult which is a different object with different members/methods.
    The Waitone still works, but when I call the EndValidateUser, I got an exception saying 
    "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.\nParameter name: value\n  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_delegate_end_invoke (object,intptr)\n  at (wrapper delegate-end-invoke) <Module>:end_invoke_object__this___object[]&_IAsyncResult (object[]&,System.IAsyncResult)\n  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters, System.IAsyncResult result) [0x0001f] in <475dec2c1fe44b95bbfbd21b550b63f8>:0 \n  at System.ServiceModel.ClientBase`1+ChannelBase`1[TChannel,T].EndInvoke (System.String methodName, System.Object[] args, System.IAsyncResult result) [0x00045] in <475dec2c1fe44b95bbfbd21b550b63f8>:0 \n

    Any idea's or approaches on how to solve this ?

    Regards,
    Sven Peeters


    Code for Reference :

        AuthenticationContext authenticationContext = new AuthenticationContext(Static_Functions.activeDirectoryTenant);

                string aadClientAppSecret = Static_Functions.activeDirectoryClientAppSecret;
                ClientCredential creadential = new ClientCredential(Static_Functions.activeDirectoryClientAppId, aadClientAppSecret);
                AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(Static_Functions.activeDirectoryResource, creadential).Result;
                string oAuthHeader = authenticationResult.CreateAuthorizationHeader();

                string serviceName = "PWBMobilityServiceGroup";
                string soapServiceUriString = Static_Functions.GetSoapServiceUriString(serviceName, Static_Functions.aosUri);

                EndpointAddress endpointAddress = new EndpointAddress(soapServiceUriString);
                System.ServiceModel.Channels.Binding binding = Static_Functions.GetBinding();

                SchindlerTechAssist.Droid.D365Service.MobilityServiceClient client = new SchindlerTechAssist.Droid.D365Service.MobilityServiceClient(binding, endpointAddress);
                IClientChannel dimServiceChannel = client.InnerChannel;

                using (OperationContextScope dimServiceOperContext = new OperationContextScope(dimServiceChannel))
                {
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers[Static_Functions.OAuthHeader] = oAuthHeader;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                    CallContext callContext = new CallContext { Company = "DAT" };

                    string empId = "000509";
                    string pass = "test";

                    #region Validate User

                    SchindlerTechAssist.Droid.D365Service.PWBMobServiceValidateUserRequest validateUserRequest = new SchindlerTechAssist.Droid.D365Service.PWBMobServiceValidateUserRequest();
                    validateUserRequest.EmployeeId = empId;
                    validateUserRequest.Password = pass;

                    SchindlerTechAssist.Droid.D365Service.MobilityService service = (SchindlerTechAssist.Droid.D365Service.MobilityService)dimServiceChannel;

                    var resultAsync = service.BeginValidateUser(validateUserRequest, null, null);
                    resultAsync.AsyncWaitHandle.WaitOne();

                    var result = service.EndValidateUser(resultAsync);


                    #endregion

                }
    Thursday, January 25, 2018 6:19 AM

All replies

  • Hi Sven,

    >> used the Silverlight SDK to create the service reference proxy class and also added the necessary framework references.

    Could you share us the Service Contract and the command to generate proxy class?

    I make a test with code below:

    And command below:

    It will generate ValidateUserAsync method instead of BeginValidateUser and EndValidateUser.

    Did you test the Xamarin App in simulator or physical phone?

    Could you share us the endpoint address for Xamarin app?

    I make a test by publishing the WCF Service to IIS, and change the endpoint address like http://ip address/ HelloWorldService.svc, it works correctly.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 26, 2018 7:10 AM
  • Hi Tao,

    I've received some feedback on another forum, might be related to TLS 1.2 which is not enabled by default. I'll get back to this as soon as I was able to test this ...

    Monday, January 29, 2018 8:41 AM
  • Hi Sven,

    If you got any update about this issue, please feel free to let us know.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 31, 2018 2:41 AM
  • Hi All,

    Couldn't find the culprit I'm afraid so I switched to OData instead of SOAP.

    There is an extra convertion between JSON and CRL Object, but shouldn't notice a perf impact.

    Regards,

    Sven Peeters

    Thursday, March 22, 2018 8:21 AM