Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Calling a WCF Soap Service

$
0
0

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) :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.ClientBase1+ChannelBase1[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

        }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>