GVKun编程网logo

asp.net – Xamarin.iOS推送通知标记.NET API / Azure通知中心

22

对于asp.net–Xamarin.iOS推送通知标记.NETAPI/Azure通知中心感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于2195端口是强制要求打开的?IOS推送通知在php中不起

对于asp.net – Xamarin.iOS推送通知标记.NET API / Azure通知中心感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于2195端口是强制要求打开的? IOS 推送通知在 php 中不起作用,而 Ios 推送通知未在 laravel 中进入移动设备、ASP.NET 5 API – Azure AD B2C、asp.net Core/OnPostAsync:防止记录被创建两次的最佳方法是什么? 获取/重定向/发布页面加载通知系统通知端点推送通知、asp.net – 适用于多个用户的EWS通知中心的有用信息。

本文目录一览:

asp.net – Xamarin.iOS推送通知标记.NET API / Azure通知中心

asp.net – Xamarin.iOS推送通知标记.NET API / Azure通知中心

我们正在使用Xamarin.Forms开发跨平台( Android和iOS)应用程序.到目前为止,我们设法让应用程序正常运行,所以很酷!

我们在我们的应用程序中包含了一些推送通知,使用Azure通知中心,GCM(适用于Android)和APNS(适用于iOS).它工作得很好!

实际上,我们只有最后一个问题:Android的一切正常,我们也可以使用iOS注册推送通知,但我们无法在注册中添加一些标签.

实际上,我们需要能够向一个用户或一组用户发送推送通知,而不是向所有人发送推送通知.为此,我们在web api的方法中这样做:

if (user.DeviceType.Equals("Android"))
{
   registration = new GcmRegistrationDescription(handles.Handle);

}
else
{
   registration = new AppleRegistrationDescription(handles.Handle);
}
registration.Tags = new HashSet<string>();
registration.Tags.Add("usermail:" + user.Email);
registration.Tags.Add("userid:" + user.Id);
registration.Tags.Add("userdevice:" + user.DeviceType);
registration.Tags.Add("usertype:" + tag);
registration.RegistrationId = handles.RegistrationId;
await NotificationHelper.Hub.CreateOrUpdateRegistrationAsync(registration);

对于给定的Handle,我们在Android中以这种方式检索它:

protected override void OnRegistered(Context context,string registrationId)
{
   [...] //the registration id is given in args
}

这种方式在iOS中:

public override void RegisteredForRemoteNotifications(UIApplication application,NSData devicetoken)
{
   [...]

   var Devicetoken = devicetoken.Description;

   if (!string.IsNullOrWhiteSpace(Devicetoken))
   {
      Devicetoken = Devicetoken.Trim('<').Trim('>');
   }

   Userinformations.Handles.RegistrationId = Devicetoken.Replace(" ","").toupper();

   [...]
}

在Android中一切正常(我能够添加标签)但是我的iOS出错了.这条线

await
NotificationHelper.Hub.CreateOrUpdateRegistrationAsync(registration);

正在生成异常,告诉我我的registrationId“不再有效”.您可以注意到我在iOS的registrationId中删除了间距,因为如果我没有,我会收到另一个错误,告诉我我的registrationID包含非十六进制字符.

我不知道该怎么做才能解决这个问题,我在iOS中检索错误的registrationId,还是为APNS添加标签不同的方法?

谢谢你的帮助 !

编辑:我注意到设备令牌必须是大写的.但令人惊讶的是,我得到了同样的错误.这里有2个截图,以帮助您了解:

enter image description here


enter image description here

所以你可以看到,在我的注册中,我在Devicetoken中获得的内容以及我在RegistrationId中获得的内容是相同的……我不知道该怎么做:/

解决方法

实际上有很多在线文档和帖子帖子告诉你调整你从iOS方法’RegisteredForRemoteNotifications’获得的设备令牌.但是,如果你查看官方文档,这不是正确的方法.

以下是我们的“RegisteredForRemoteNotifications”方法的片段,因为您可以看到我们对设备令牌没有任何操作,请试一试,如果这样可以解决您的问题,请告诉我.

if (oldDevicetoken != null)
            {
                if (oldDevicetoken.ToString() != devicetoken.ToString())
                {
                    try
                    {
                        Hub.UnregisterallAsync(oldDevicetoken,(error) =>
                        {
                            //check for errors in unregistration process.
                            if (error != null)
                            {
                                TestingLogs.ApplicationLog.AppendFile(DateTime.Now.ToString() + "  :  " + "[PNS EXCEPTION] - Exception has been hit! - Message: " + error + " | Source: " + "Unregistering old device token against the notification hub.");
                                //exit out of the code here because we can't keep our hub clean without being able to remove the device from our registration list.
                                return;
                            }
                            else
                            {
                                ShouldComplete = true;
                            }
                        });
                    }
                    catch (Exception genEx)
                    {
                        TestingLogs.ApplicationLog.AppendFile(DateTime.Now.ToString() + "  :  " + "[PNS EXCEPTION] - Exception has been hit! - Message: " + genEx.Message + " | Source: " + genEx + Environment.NewLine + Environment.NewLine);
                    }
                }
            }
            else
            {
                // Store current device token 
                bool res = await ApplicationSettings.StoreDevicetoken(devicetoken);
            }

            // Check if we need to perform our initial registrations

            if (ShouldComplete)
            {
                NSSet RegisteredTags = await ApplicationSettings.RetrieveUserTags();

                if (RegisteredTags == null)
                {
                    RegisteredTags = new NSSet("AppleDevice");
                }

                //Register the device against the notification hub keeping the details accurate at all times.
                Hub.RegisterNativeAsync(devicetoken,RegisteredTags,(errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        TestingLogs.ApplicationLog.AppendFile(DateTime.Now.ToString() + "  :  " + "[PNS EXCEPTION] - Exception has been hit! - Message: " + errorCallback + " | Source: " + "Registering device token against the notification hub.");
                    }
                    else
                    {
                        if (devicetoken != null)
                        {
                            NSUserDefaults.StandardUserDefaults.SetString("Completed","InitialTagRegistration");
                            NSUserDefaults.StandardUserDefaults.Synchronize();
                        }
                    }
                });
            }

2195端口是强制要求打开的? IOS 推送通知在 php 中不起作用,而 Ios 推送通知未在 laravel 中进入移动设备

2195端口是强制要求打开的? IOS 推送通知在 php 中不起作用,而 Ios 推送通知未在 laravel 中进入移动设备

如何解决2195端口是强制要求打开的? IOS 推送通知在 php 中不起作用,而 Ios 推送通知未在 laravel 中进入移动设备?

我正在使用 PHP 代码发送推送通知,而 ios 没有收到通知,所以我不知道确切的问题是什么,请帮忙。

public static function ios_push($device_token,$title,$msg,$description,$type = "",$r_type = "")
{
    \Log::info(''device_token'',[''context'' => $device_token]);
    \Log::info($device_token);

    $badge_count =2;
    $streamContext = stream_context_create();

    $connectTimeout = 60;

    stream_context_set_option($streamContext,''ssl'',''passphrase'',IPHONE_CERTIFICATE_PASSWORD);

    \Log::info(IPHONE_CERTIFICATE_TYPE);

    if(IPHONE_CERTIFICATE_TYPE == "Development") 

    {

      //For Development

      stream_context_set_option($streamContext,''local_cert'',IOS_PUSH_DEV_PEM_PATH);

      $apns = stream_socket_client(''ssl://gateway.push.apple.com:2195'',$error,$errorString,$connectTimeout,STREAM_CLIENT_CONNECT |STREAM_CLIENT_PERSISTENT,$streamContext);

    } 

    else 

    {

      //For Production 

      stream_context_set_option($streamContext,WWW_ROOT_PATH.IOS_PUSH_DEV_PEM_PATH);

      $apns = stream_socket_client(''ssl://gateway.push.apple.com:2195'',$streamContext);

    }

    if (!$apns) {
        \Log::info(''Error : ''.$error.'' ''.$errorString);
    } else {
        \Log::info("success");
    }

    $music = ''default'';

    $payload[''aps''] = array(''alert'' => [''title''=>$title,''body''=>$msg],''badge'' => $badge_count,''title''=>$description,''sound''=> $music,''notification_type'' =>  $type);

    //$payload[''aps''] = array(''alert'' => "vikas",''notification_type'' =>  $type);

    // $data[''notification_type''] = $notification_type;

    // $data[''sender_first_name''] = $sender_first_name;

    // $data[''sender_last_name''] = $sender_last_name;

    // $data[''sender_user_id''] = $sender_user_id;

    $data[''sound''] = $music;

    $data[''title''] = $title;

    $data[''notification_type''] = $type;

    $data[''report_type''] = !empty($r_type) ? substr($r_type,-8) : "";

    $payload[''data''] = $data;



    $payload = json_encode($payload);

    \Log::info(''Log message'',[''payload'' => json_encode($payload)]);



    $apnsMessage = chr(0) . pack(''n'',32) . pack(''H*'',$device_token) . pack(''n'',strlen($payload)) . $payload; 

    $fwriteRes = fwrite($apns,$apnsMessage,strlen($apnsMessage));     

    fclose($apns);

    return true;

}

这是我的职责

但是IOS在移动端没有收到任何通知

有什么问题

2195端口的问题已经解决了,这是为什么?

解决方法

我认为现在使用端口 443

Sending Notification Requests to APNs

https://support.apple.com/en-us/HT203609

https://developer.apple.com/documentation/usernotifications/sending_push_notifications_using_command-line_tools?language=objc

我一直在通过开发者门户与 Apple 进行交流,到目前为止我所知道的就这些。我现在决定只是挑选一下,看看其他使用 APNS 的开发人员如何确保交付成功。我也问过这个问题,现在我正在浏览 Apple-Push-Notifications 标签,我看到其他人也在。

,

这个解决方案对我很有帮助!!!!

-----------) 第 1 步

首先你需要安装这个作曲家库。

compose require lcobucci/jwt:^3.3.1

----------) 第 2 步

然后编写代码,例如..

use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Ecdsa\Sha256; 

public static function generateiosauthtoken() {
    $key = file_get_contents(''Your p8 file'');  // p8 file
    $signer = new Sha256();
    $time = time();
    return  (new Builder())->issuedBy("TEAMID") // iss claim
            ->permittedFor(''https://appleid.apple.com'') // aud claim
            ->expiresAt($time + 3600) // exp claim
            ->issuedAt($time) // iat claim
            ->withHeader(''kid'',"KEYID") // kid header
            ->getToken($signer,new Key($key));
}


public static function ios_push($device_token,$title,$msg,$description)
{
    $token = ApiHelper::generateiosauthtoken();
    $music = ''default'';
    $payload[''aps''] = array(''alert'' => [''title''=>$title,''body''=>$msg],''badge'' => 1,''title''=>$description,''sound''=> $music,''notification_type'' =>  $type);
    $data[''sound''] = $music;
    $data[''title''] = $title;
    $payload[''data''] = $data;
    $payload = json_encode($payload);

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_HTTP09_ALLOWED,true);
    curl_setopt_array($curl,array(
      CURLOPT_PORT => "443",CURLOPT_URL => "https://api.push.apple.com:443/3/device/".$device_token."",CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => "",CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 30,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,CURLOPT_CUSTOMREQUEST => "POST",CURLOPT_POSTFIELDS => $payload,CURLOPT_HTTPHEADER => array(
        "apns-topic: bundleid",// put it here your aplication bundle id
        "authorization: bearer ".$token."",),));

    $response = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    if ($err) {
      $arr = array("code" => 400,"msg" => $err,"flag" => false,"data" => (object)array());
      \Response::json($arr);
    } else {
      echo $response;
    }
}

ASP.NET 5 API – Azure AD B2C

ASP.NET 5 API – Azure AD B2C

我正在开发应用程序,几乎完成了我的前端.
所以我想从后端开始.

我曾经在ASP.NET 4中进行编程,但是由于我启动了一个全新的应用程序(B2C和B2B),所以我认为在ASP.NET 5 API中可能很有趣.

现在我最大的问题是身份验证.
模板中没有提供标准的实现.

我只对Azure AD认证感兴趣,并喜欢Azure B2C AD真正削减了优势.

我只在ASP.NET 4中找到使用Azure AD B2C的文档.
经过几个小时的搜索,我仍然没有找到关于在ASP.NET 5 API中使用Azure AD B2C的文档.

有人可以帮我查找正确的文档或者帮助我吗?

解决方法

有一篇来自Microsoft的新文章是将Azure AD集成到ASP.NET 5 Web应用程序中:
https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-webapp-openidconnect-aspnet5/

我想这是你正在寻找的.

顺便说一句,您可能还想查看Azure AD B2C限制和限制:
https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-limitations/

asp.net Core/OnPostAsync:防止记录被创建两次的最佳方法是什么? 获取/重定向/发布页面加载通知系统通知端点推送通知

asp.net Core/OnPostAsync:防止记录被创建两次的最佳方法是什么? 获取/重定向/发布页面加载通知系统通知端点推送通知

您主要有三个选择:

  1. 优化保存操作
  2. 异步调用表单提交
  3. 切换到异步 API 模式

优化保存操作

嗯,这是一个简单的答案。您的操作时间很长并且给您的用户带来了一些挫败感?优化。当然,并不是所有的操作都可以让用户跑得这么快没有挫败感。然而,这并不是唯一的答案。也许您会在下面找到一些有趣的选项,这不是懒惰的理由,也不是因为某些性能问题而跳过查看代码的理由。

异步提交表单

异步调用表单需要您在提交表单时阻止浏览器导航。相反,使用客户端代码禁用表单并向用户显示进度动画。这将防止他们多次提交表单。然后通过 XHR 向服务器异步发送 HTTP POST 请求。操作完成后,向用户显示一条消息和/或导航到下一页。此技术不需要对您当前的服务器端实现进行任何更改,但不能很好地扩展。此外,它会将您的用户锁定在“请稍等”的心态中,但有时这实际上是最相关的用户体验。

异步 API 模式

异步 ​​API 模式是一种更改服务器端实现的模式。提交表单后,post 查询处理程序只对数据进行一些快速的内容验证,然后立即返回。之后服务器会在后台做长时间的操作,你的应用程序必须实现一个通知系统来向用户提供进度信息。通知系统可以是轮询或推送。

获取/重定向/发布

此模式最常见的实现是 Post/Redirect/Get 模式。 OnPostAsync() 方法将在验证表单并准备开始操作后向用户返回重定向响应。这会将用户转发到另一个等待任务完成的页面。它易于实施,但不能提供出色的用户体验。

页面加载通知系统

在这种方法中,我们向应用程序中的每个页面(通常在一种主模板中)添加一个通知系统。该组件将查找要显示给用户的消息,并将它们插入到文档中。当用户提交表单(通过导航或 XHR)时,只做一些快速验证和返回。您可以添加一条消息以确认操作已成功启动。开始后台操作,完成后,向用户添加一条消息。在导航时,用户最终会收到操作成功或失败的通知。

通知端点

另一种解决方案是实现一个小型 API,允许客户端查询长时间运行的操作状态。每当用户在池中有正在运行的任务时,向客户端添加一些代码,这些代码将定期调用该端点以获取操作进度。使用该信息来显示通知,或者如果有动机(并且如果该过程允许轻松计算进度百分比),您甚至可以显示在该过程中填满的进度条。然后更新您的服务器端操作以向通知系统提供频繁的进度信息。如果结合 XHR 表单提交,用户无需任何导航即可开始和完成长时间运行的操作。

推送通知

此技术需要一些现代技术,例如 SignalR,但可提供最佳性能和用户体验。首先,应用程序将与服务器建立双工通信。现在,服务器可以直接将消息流式传输到客户端。客户端不再需要花费大部分资源轮询服务器,他们只需发送表单内容。服务器不需要扩展以回复数百万用户自上一秒以来没有任何变化,它只需要处理表单提交。此外,您无需等待用户轮询服务器以向他提供反馈。你可以实时做到这一点。

asp.net – 适用于多个用户的EWS通知中心

asp.net – 适用于多个用户的EWS通知中心

我正在尝试创建一个服务来将交换通知推送到asp.net应用程序,最终使用SignalR.

我的计划是创建一个通知中心,在每个用户登录到asp应用程序时为其预订,并为他们监听通知.当收到通知时,项目的第二部分是使用signalR仅向每个用户发送正确的通知.一旦他们注销或超时,通知中心将取消订阅.

到目前为止,我已经完成了一些基本的测试,并且可以通过我的凭证硬编码在一个小的控制台应用程序中接收通知.我正在努力的是如何同时为多个人这样做.例如,我是否必须为每个用户创建单独的线程,还是有更好的方法?

我想无论我不得不使用模仿而不是持有每个用户的凭据吗?如果每个用户都有活动会话,我还必须找到一种自动刷新超时的方法.

下面是我发现并且一直在玩的一些代码,我将很感激任何想法或任何人可以分享我如何能够最好地实现这一目标的例子.

非常感谢

安迪

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices.Data;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
                service.Url = new Uri("https://server/EWS/Exchange.asmx");
                service.Credentials = new NetworkCredential("user","pass","domain");
                SetStreamingNotifications(service); 
                while (true)
                { }


        }

        static void SetStreamingNotifications(ExchangeService service)
        {
            // Subscribe to streaming notifications on the InBox folder,and listen
            // for "NewMail","Created",and "Deleted" events.
            StreamingSubscription streamingsubscription = service.SubscribetoStreamingNotifications(
                new FolderId[] { WellKNownFolderName.Calendar,WellKNownFolderName.InBox },EventType.Created,EventType.Modified);

            StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service,9);

            connection.AddSubscription(streamingsubscription);
            // Delegate event handlers.
            connection.OnNotificationEvent +=
                new StreamingSubscriptionConnection.NotificationEventDelegate(OnEvent);
            connection.OnSubscriptionError +=
                new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnError);
            connection.Ondisconnect +=
                new StreamingSubscriptionConnection.SubscriptionErrorDelegate(Ondisconnect);
            connection.open();

            Console.WriteLine("--------- StreamSubscription event -------");
        }

        static private void Ondisconnect(object sender,SubscriptionErrorEventArgs args)
        {
            // Cast the sender as a StreamingSubscriptionConnection object.          
            StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
            // Ask the user if they want to reconnect or close the subscription.
            ConsoleKeyInfo cki;
            Console.WriteLine("The connection to the subscription is disconnected.");
            Console.WriteLine("Do you want to reconnect to the subscription? Y/N");
            while (true)
            {
                cki = Console.ReadKey(true);
                {
                    if (cki.Key == ConsoleKey.Y)
                    {
                        connection.open();
                        Console.WriteLine("Connection open.");
                        break;
                    }
                    else if (cki.Key == ConsoleKey.N)
                    {
                        // The ReadKey in the Main() consumes the E.
                        Console.WriteLine("\n\nPress E to exit");
                        break;
                    }
                }
            }
        }

        static void OnEvent(object sender,NotificationEventArgs args)
        {
            StreamingSubscription subscription = args.Subscription;

            // Loop through all item-related events.
            foreach (NotificationEvent notification in args.Events)
            {

                switch (notification.EventType)
                {
                    case EventType.NewMail:
                        Console.WriteLine("\n-------------Mail created:-------------");
                        break;
                    case EventType.Created:
                        Console.WriteLine("\n-------------Item or folder created:-------------");
                        break;
                    case EventType.Deleted:
                        Console.WriteLine("\n-------------Item or folder deleted:-------------");
                        break;
                }
                // display the notification identifier.
                if (notification is ItemEvent)
                {
                    // The NotificationEvent for an e-mail message is an ItemEvent.
                    ItemEvent itemEvent = (ItemEvent)notification;
                    Console.WriteLine("\nItemId: " + itemEvent.ItemId.UniqueId);

                }
                else
                {
                    // The NotificationEvent for a folder is an FolderEvent.
                    //FolderEvent folderEvent = (FolderEvent)notification;
                    //Console.WriteLine("\nFolderId: " + folderEvent.FolderId.UniqueId);
                }
            }
        }
        static void OnError(object sender,SubscriptionErrorEventArgs args)
        {
            // Handle error conditions.
            Exception e = args.Exception;
            Console.WriteLine("\n-------------Error ---" + e.Message + "-------------");
        }
    }
}

解决方法

我解决这个问题的方法是:

>拥有一个有权冒充所有用户的帐户.
>我通过提供用户名和帐户为该帐户创建服务
密码.
>我冒充用户并将用户的订阅添加到
连接
>我创建了另一个服务,它是主服务的关闭
相同的用户名和密码,将冒充其他用户
然后将订阅添加到同一连接

这是我的代码的两个部分.忘记LogDevice它只是内部的东西.
第一部分是详细的模拟并将服务添加到服务列表中
在我的情况下,服务列表是一个字典,userSMTP是密钥,这里的UserSMTP密钥是模拟帐户.

/// <summary>
    /// Impersonate one user at a time and without using the autodiscovery method to find the proper url for the userSmtp,/// and copy the provided url to the usersmtp.
    /// </summary>
    /// <param name="url"> </param>
    /// <param name="userSmtp">user smtp</param>
    /// <param name="enableTrace">to enable logging from the XML tracing </param>
    /// <param name="exchangeVersion">Exchange server version used</param>
    private Uri ImpersonateUser(Uri url,string userSmtp,bool enableTrace,ExchangeVersion exchangeVersion)
    {
        Uri result = url;
        var log = "ImpersonateUser \n";
        try
        {
            log += "0/8 Checking services redundancy\n";
            if (Services.ContainsKey(userSmtp))
            {
                Services.Remove(userSmtp);
            }
            log += "1/8 Create a new service for " + userSmtp + "\n";
            var service = new ExchangeService(exchangeVersion);

            log += "2/8 Get credentials for the service\n";
            var serviceCred = ((System.Net.NetworkCredential)(((WebCredentials)(Services.First().Value.Credentials)).Credentials));

            log += "3/8 Assign credentials to the new service\n";
            service.Credentials = new WebCredentials(serviceCred.UserName,serviceCred.Password);

            log += "4/8 TraceEnabled is" + enableTrace.ToString() + "\n";
            service.TraceEnabled = enableTrace;

            log += "5/8 Get the Url for the  service with AutodiscoverUrl \n";
            service.Url = url;

            log += "6/8 Assign a new ImpersonatedUserId to the new service for" + userSmtp + "\n";
            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,userSmtp);

            try
            {
                log += "7/8 Validating the impersonation\n";
                RuleCollection rulecoll = service.GetInBoxRules();
            }
            catch (Exception ex)
            {
                _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUser: Failed to validate the impersonation for {0}\n Exception: {1}\n",userSmtp,ex.Message);
                int hr = System.Runtime.InteropServices.Marshal.GetHRForException(ex);

                if (hr == -2146233088) // We do not have right to impersonate this user.
                {
                    result = null;
                    return result;
                }
                else
                {
                    _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUser(2): trying to resolve {0} with Autodiscover instead...",userSmtp);
                    result = ImpersonateUser(userSmtp,enableTrace,exchangeVersion);
                }

            }

            log += "8/8 Adding the service \n";
            if (!Services.ContainsKey(userSmtp))
            {
                Services.Add(userSmtp,service);
                _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUser(2): {0} has been impersonated\n",service.ImpersonatedUserId.Id);
            }
        }
        catch (Exception ex)
        {
            _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUser(2): exception {0}\n The exception occured after the following steps: \n{1}",ex.Message,log);
        }
        return result;
    }

以下是调用上一个函数(即对所有用户)的代码,请记住,您应该以某种方式存储要模拟的每个帐户的电子邮件地址.

/// <summary>
        /// To Impersonate users in order to get the info from them. 
        /// </summary>
        /// <param name="userSmtps">List of users to be impersonated</param>
        /// <param name="enableTrace"> To enable logging from the XML tracing</param>
        /// <param name="exchangeVersion">Exchange server version used </param>
        public void ImpersonateUsers(ICollection<string> userSmtps)
        {
            var log = "ImpersonateUsers\n";
            var firstUserSmtp = "";
            if (userSmtps != null)

                if (userSmtps.Count > 0)
                {

                    //the url for the first smtp
                    try
                    {
                        log += "1/2 Impersonating the first userSmtp\n";
                        _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUsers:  Getting the Url from the autodiscovery for the first smtp {0} ",userSmtps.First());
                        bool enableTrace = Services.First().Value.TraceEnabled;

                        ExchangeVersion exchangeVersion = Services.First().Value.RequestedServerVersion;
                        firstUserSmtp = userSmtps.First();
                        var commonSmtpUrl = ImpersonateUser(userSmtps.First(),exchangeVersion);
                        if (commonSmtpUrl == null) userSmtps.Remove(firstUserSmtp);
                        // If the list contains other than the first one 
                        log += "2/2 Impersonating " + (userSmtps.Count - 1) + " userSmtps\n";

                        if (userSmtps.Count >= 1)
                        {
                            foreach (var userSmtp in userSmtps)
                            {
                                try
                                { //skip ther first one because it is already impersonated. 
                                    if (userSmtp == firstUserSmtp)
                                    {
                                        continue;
                                    }
                                    // Impersonate the users
                                    _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUsers:  Impersonating {0} ...",userSmtp);

                                        commonSmtpUrl = ImpersonateUser(userSmtp,exchangeVersion);

                                }
                                catch (Exception ex)
                                {
                                    _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUsers: Impersonating {1}\n exception {0}\n",userSmtp);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        _logDevice.LogSrvMessage(1,"ExchangeLiteService: ImpersonateUsers: exception {0}\n The exception occured after the following steps: \n{1}",log);
                    }
                }
        }

我会把订阅部分和添加到连接,但它有点难看,很难得到.但想法只是你应该有一个连接,然后你去你做的每个服务,然后`connection.AddSubscription(streamingSubscription);其中streamingSubscription是从服务中提取的.

我们今天的关于asp.net – Xamarin.iOS推送通知标记.NET API / Azure通知中心的分享已经告一段落,感谢您的关注,如果您想了解更多关于2195端口是强制要求打开的? IOS 推送通知在 php 中不起作用,而 Ios 推送通知未在 laravel 中进入移动设备、ASP.NET 5 API – Azure AD B2C、asp.net Core/OnPostAsync:防止记录被创建两次的最佳方法是什么? 获取/重定向/发布页面加载通知系统通知端点推送通知、asp.net – 适用于多个用户的EWS通知中心的相关信息,请在本站查询。

本文标签: