exchange webservice访问类(日程新增和删除)

输出错误信息:

                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items.Length.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items[0].MessageText);
                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items[0].MessageXml.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items[0].ResponseClass.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items[0].ResponseCodeSpecified.ToString());
                 assistant.WriteFile("C:\\DEBUG.txt", "Length:" + diResponse.ResponseMessages.Items[0].ResponseCode.ToString());

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Text;
using HPCalendarSyncToPT1.Common;
using HPCalendarSyncToPT1.Exchange;

namespace HPCalendarSyncToPT1
{
public class ExchangeWebService
{
ExchangeServiceBinding esb = null;
public ExchangeWebService(string account, string password, string domain)
{
esb = new ExchangeServiceBinding();
esb.Credentials = new NetworkCredential(account, password, domain);
esb.Url = ConfigurationManager.AppSettings["pt1exchange_ws_url"];
}

public bool DeleteItem(string itemId, string changeKey)
{
bool result = false;
DeleteItemType d = new DeleteItemType();
ItemIdType id = new ItemIdType();
id.Id = itemId;
id.ChangeKey = changeKey;
d.ItemIds = new ItemIdType[] {id};
d.SendMeetingCancellations = CalendarItemCreateOrDeleteOperationType.SendToNone;
d.SendMeetingCancellationsSpecified = true;
DeleteItemResponseType deleteItemResponse = esb.DeleteItem(d);

if (deleteItemResponse != null)
{
if (deleteItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
{
Console.WriteLine(deleteItemResponse.ResponseMessages.Items[0].MessageText);
}
else
{
Console.WriteLine("删除日程成功!");
result = true;
}
}
return result;
}

public ExchangeCalendarItemResult CreateAppointmentEWS(Calendar item)
{
// Create the appointment.
CalendarItemType appointment = new CalendarItemType();

// Add item properties to the appointment.
appointment.Body = new BodyType();
appointment.Body.BodyType1 = BodyTypeType.Text;
appointment.Body.Value = "";//正文内容
//appointment.Categories = new string[] { "aaa","bbb" };//类别
appointment.Importance = ImportanceChoicesType.High;
appointment.ImportanceSpecified = true;
appointment.ItemClass = "IPM.Appointment";
appointment.Subject = item.Subject;//标题

// Add calendar properties to the appointment.
appointment.Start = item.StartTime;
appointment.StartSpecified = true;
appointment.End = item.EndTime;
appointment.EndSpecified = true;
//appointment.HasAttachments = item.HasAttachment;

 

// Identify the destination folder that will contain the appointment.
DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
folder.Id = DistinguishedFolderIdNameType.calendar;

// Create the array of items that will contain the appointment.
NonEmptyArrayOfAllItemsType arrayOfItems = new NonEmptyArrayOfAllItemsType();
arrayOfItems.Items = new ItemType[1];

// Add the appointment to the array of items.
arrayOfItems.Items[0] = appointment;

// Create the CreateItem request.
CreateItemType createItemRequest = new CreateItemType();

// The SendMeetingInvitations attribute is required for calendar items.
createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
createItemRequest.SendMeetingInvitationsSpecified = true;

// Add the destination folder to the CreateItem request.
createItemRequest.SavedItemFolderId = new TargetFolderIdType();
createItemRequest.SavedItemFolderId.Item = folder;

// Add the items to the CreateItem request.
createItemRequest.Items = arrayOfItems;

ExchangeCalendarItemResult r = null;
try
{
// Send the request and get the response.
CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);

// Get the response messages.
ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;

foreach (ResponseMessageType rmt in rmta)
{
ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;
ItemType[] items = itemArray.Items;

// Get the item identifier and change key for each item.
r = new ExchangeCalendarItemResult();
if (items != null)
foreach (ItemType itm in items)
{
Console.WriteLine("Item identifier: " + itm.ItemId.Id);
Console.WriteLine("Item change key: " + itm.ItemId.ChangeKey);
r.ItemId = itm.ItemId.Id;
r.ItemKey = itm.ItemId.ChangeKey;
}
}
}
catch (Exception e)
{
Console.WriteLine("Error Message: " + e.Message);
}
return r;
}
}
}

转载于:https://my.oschina.net/weiqinxue/blog/725292

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微服务访问webservice是一种在分布式系统中实现服务调用的方法。微服务架构的特点是将系统拆分成多个独立部署的服务,每个服务负责完成特定的业务功能。而webservice是一种用于不同应用程序之间进行通信的标准化协议,它基于HTTP和SOAP协议,并使用XML格式进行数据交换。 在微服务架构中,当一个服务需要访问webservice时,可以通过以下几个步骤进行: 1. 生成webservice客户端:首先,根据webservice的WSDL(Web Services Description Language)文档,生成相应的客户端代码。这个客户端代码可以是使用各种编程语言生成的,如Java、C#等。 2. 配置webservice访问参数:在生成的客户端代码中,需要配置webservice访问地址、调用方法以及传递的参数等信息。这些配置通常可以通过配置文件或代码进行设置。 3. 发起webservice请求:在服务代码中,通过调用生成的webservice客户端代码的相应方法,可以发起webservice请求。在请求中,可以传递需要的参数,并指定相应的处理逻辑。 4. 处理webservice响应:当webservice请求被发送后,webservice服务器会返回相应的响应数据。在客户端代码中,可以获取并处理这个响应数据,通常是解析XML格式的返回数据,提取所需的信息。 5. 调用webservice结果:最后,根据webservice的响应结果,可以在微服务中继续执行其他的相关业务逻辑。可以根据具体的需求,将webservice返回的数据用于展示、计算或者存储等处理。 总之,通过以上步骤,微服务可以方便地访问webservice,实现与其他应用程序之间的数据交互和功能调用。这种方式可以更好地实现系统的解耦和灵活性,并提供更好的可扩展性和维护性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值