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 :
<div> AuthenticationContext authenticationContext = new AuthenticationContext(Static_Functions.activeDirectoryTenant);</div> <div> </div> <div> string aadClientAppSecret = Static_Functions.activeDirectoryClientAppSecret;</div><div> ClientCredential creadential = new ClientCredential(Static_Functions.activeDirectoryClientAppId, aadClientAppSecret);</div> <div> AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(Static_Functions.activeDirectoryResource, creadential).Result;</div> <div> string oAuthHeader = authenticationResult.CreateAuthorizationHeader();</div> <div> </div> <div> string serviceName = "PWBMobilityServiceGroup";</div> <div> string soapServiceUriString = Static_Functions.GetSoapServiceUriString(serviceName, Static_Functions.aosUri);</div> <div> </div> <div> EndpointAddress endpointAddress = new EndpointAddress(soapServiceUriString);</div><div> System.ServiceModel.Channels.Binding binding = Static_Functions.GetBinding();</div> <div> </div> <div> SchindlerTechAssist.Droid.D365Service.MobilityServiceClient client = new SchindlerTechAssist.Droid.D365Service.MobilityServiceClient(binding, endpointAddress);</div> <div> IClientChannel dimServiceChannel = client.InnerChannel;</div> <div> </div> <div> using (OperationContextScope dimServiceOperContext = new OperationContextScope(dimServiceChannel))</div><div> {</div> <div> HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();</div> <div> requestMessage.Headers[Static_Functions.OAuthHeader] = oAuthHeader;</div><div> OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;</div> <div> </div> <div> CallContext callContext = new CallContext { Company = "DAT" };</div><div> </div> <div> string empId = "000509";</div> <div> string pass = "test";</div> <div> </div> <div> #region Validate User</div> <div> </div><div> SchindlerTechAssist.Droid.D365Service.PWBMobServiceValidateUserRequest validateUserRequest = new SchindlerTechAssist.Droid.D365Service.PWBMobServiceValidateUserRequest();</div> <div> validateUserRequest.EmployeeId = empId;</div> <div> validateUserRequest.Password = pass;</div> <div> </div> <div> SchindlerTechAssist.Droid.D365Service.MobilityService service = (SchindlerTechAssist.Droid.D365Service.MobilityService)dimServiceChannel;</div><div> </div> <div> var resultAsync = service.BeginValidateUser(validateUserRequest, null, null);</div> <div> resultAsync.AsyncWaitHandle.WaitOne();</div> <div> </div> <div> var result = service.EndValidateUser(resultAsync);</div> <div> </div> <div> </div> <div> #endregion</div> <div> </div> <div> }</div>