【问题标题】:Service Reference in Xamarin.Android issueXamarin.Android 问题中的服务参考
【发布时间】:2018-01-24 16:34:32
【问题描述】:

我正在尝试开发连接到 Dynamics 365 Finance And Operation 自定义 Web 服务的 Xamarin 应用程序(Xam 4.7.10.38 和 Xam.And.SDK 8.0.2.1 使用 PCL 方法)。 总结一下,就是一个 WCF Soap 服务,使用 Azure Active Directory Client Id + Client Secret 来连接到soap服务。

我已经发布了下面代码中最重要的部分以供参考。

按照指示,我使用 Silverlight SDK 创建了服务引用代理类,并添加了必要的框架引用。 然后我将此代理类包含在我的 Android 项目中以及标准 .Net Windows 应用程序中,两者都使用 VS.Net 2017。

在我打电话给var resultAsync = service.BeginValidateUser(validateUserRequest, null, null);之前,一切都是一样的

在我的 Windows 应用程序中,它返回

System.ServiceModel.Channels.ServiceChannel.SendAsyncResult。

我执行 WaitOne 来结束它,我的 EndValidateUser 返回正确的结果。

但是在我的 Android 应用程序中,它返回

System.Runtime.Remoting.Messaging.AsyncResult

这是具有不同成员/方法的不同对象。 Waitone 仍然可以工作,但是当我调用 EndValidateUser 时,我得到了一个异常提示

"System.ArgumentOutOfRangeException: 指定的参数超出了 有效值范围。\n参数名称: value\n at (wrapper 托管到本地) 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 在 System.ServiceModel.MonoInternal.ClientRuntimeChannel.EndProcess (System.Reflection.MethodBase 方法,System.String operationName, System.Object[] 参数,System.IAsyncResult 结果)[0x0001f] in :0 \n 在 System.ServiceModel.ClientBase1+ChannelBase1[TChannel,T].EndInvoke (System.String 方法名,System.Object[] 参数,System.IAsyncResult 结果)[0x00045] in :0 \n

关于如何解决这个问题的任何想法或方法?

问候, 斯文·皮特斯

参考代码:

    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

        }

【问题讨论】:

  • 我看到了这个确切的问题。在我们的内部 Dynamics 365 Finance And Operation 自定义 Web 服务上,它正在运行。在我们的客户上,我收到了同样的错误。你克服了吗?
  • 恐怕到目前为止还没有得到任何回应 :-( 我切换到 JSON 并且效果很好

标签: android wcf xamarin soap


【解决方案1】:

我的解决方法是在 Android 属性中启用 TLS 1.2。 Dynamics 测试/生产环境需要来自客户端的 TLS 1.2。

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2011-01-10
    • 2014-07-19
    相关资源
    最近更新 更多