在VB.NET中使用EWS创建约会,我缺少什么?

时间:2012-09-28 10:46:43

标签: asp.net vb.net visual-studio-2008 exchangewebservices

您好我想向其他会员发送日历邀请,我该如何在vb.net中执行此操作, 我添加了交换网络参考,并可以向其他人发送普通邮件。

这是我到目前为止所拥有的

   Public Sub Einladungen()
        Dim esb As New ExchangeServer.ExchangeServiceBinding
        esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
        esb.Url = Session("EX_DomainURL")

        Dim appointment As CalendarItemType = New CalendarItemType

        ' Set properties on the appointment.
        appointment.Subject = "Dentist Appointment"
        appointment.Body = New BodyType
        appointment.Body.BodyType1 = BodyTypeType.Text
        appointment.Body.Value = "Agenda Items...."
        appointment.Start = New DateTime(2012, 3, 1, 9, 0, 0)
        appointment.End = appointment.Start.AddHours(2)

        appointment.Location = "Conf Room"
        appointment.RequiredAttendees.Add("user1@contoso.com")
        appointment.RequiredAttendees.Add("user2@contoso.com")
        appointment.OptionalAttendees.Add("user3@contoso.com")
        ' Save the appointment.
        appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy)
    End Sub

Visual Studio告诉我:

  

添加不是“System.Array”的成员

  

“保存”不是“ExchangeServer.CalendarItemType”

的成员

  

未声明名称“SendInvitationMode”

我缺少什么?

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

问题是您通过直接引用Exchange Web服务创建了自己的EWS代理类,但您找到的示例代码是使用Exchange Web Service Managed API构建的。

所以你应该做的是download the EWS Managed API,添加对Microsoft.Exchange.WebServices.dll的引用,并将你的代码的开头改为类似的东西:

Dim esb As New ExchangeService(ExchangeVersion.Exchange2007_SP1);
esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
esb.Url = Session("EX_DomainURL")

Dim appointment As new Appointment(esb);
// ... the rest of your code here.

您可能需要查看此示例: http://msdn.microsoft.com/en-us/library/exchange/dd633661(v=exchg.80).aspx