Quantcast
Channel: The Exchange Guide » Calendar Item
Viewing all articles
Browse latest Browse all 7

FindItem gets no error but 0 items

$
0
0

We move to production servers, and the code that I was using to get an ItemIdType from an

calendarEvent.CalendarEventDetails.ID
returns 0 Items, and no error.

I’m using that convertion because, I get the f/b of a resource, and based on that (CalendarEventDetails.ID) I need to send a Decline Meeting invitation, I use the example from the SDK to send the Decline, RespondToMeetingRequest.

But I can’t remember where I got the function to convert from Event Id to ItemIdType, or If I made from zero. It was a year ago, and it works good on lab server, but in production server I get no items.

Is difficult for me to understand Restrictions and Filters, I see the code and everything looks fine, maybe the problem is about security config in mailbox, but the Exchange Admins, told me that the user that I’m using has owner rigths over resource inbox.

Can somebody help me?????

Thanks.

This is the function:

///

///

Takes a CalendarEventDetails ID, from a GetUserAvailabiltyResponse for

///

example, and finds the CalendarItem that matches it.

///

///

///

ID property value from a CalendarEventDetails

///

Binding to make the call with

///

ItemId of the associated calendar item

public

static

Exchange.
ItemIdType

GetCalendarItemFromCalendarEvent(Exchange.
ExchangeServiceBinding

binding,
string

calendarEventDetailsId)
{

// The ID from CalendarEventDetails is a hexidecimal PR_ENTRY_ID. In

// order to use it as a restriction on FindItem, we need to convert it to

// a byte-array and base64 encode it.

//

int

i = 0;

string

hexEntryId = calendarEventDetailsId;

List

byte

> byteArray =
new

List

byte

>(hexEntryId.Length / 2);

while

(i {
byteArray.Add(

Convert

.ToByte(hexEntryId.Substring(i, 2), 16));
i = i + 2;
}

string

base64EntryId = System.
Convert

.ToBase64String(byteArray.ToArray());

// Build the conditions of the FindItem request

//

Exchange.

PathToExtendedFieldType

extendedProp =
new

Exchange.
PathToExtendedFieldType

();
extendedProp.PropertyTag =

“0x0FFF”

;
// PR_ENTRYID

extendedProp.PropertyType = Exchange.

MapiPropertyTypeType

.Binary;

Exchange.

ConstantValueType

propValue =
new

Exchange.
ConstantValueType

();
propValue.Value = base64EntryId;

Exchange.

IsEqualToType

equalToRestriction =
new

Exchange.
IsEqualToType

();
equalToRestriction.Item = extendedProp;
equalToRestriction.FieldURIOrConstant =

new

Exchange.
FieldURIOrConstantType

();
equalToRestriction.FieldURIOrConstant.Item = propValue;

Exchange.

RestrictionType

restriction =
new

Exchange.
RestrictionType

();
restriction.Item = equalToRestriction;

Exchange.

FindItemType

request =
new

Exchange.
FindItemType

();
request.Restriction = restriction;

//Identifies the item properties and content to include in a FindItem response.

request.ItemShape =

new

Exchange.
ItemResponseShapeType

();
request.ItemShape.BaseShape = Exchange.

DefaultShapeNamesType

.IdOnly;

// We know that CalendarEvents can only come from the default calendar

//

request.ParentFolderIds =

new

Exchange.
DistinguishedFolderIdType

[] {
new

Exchange.
DistinguishedFolderIdType

() };
((Exchange.

DistinguishedFolderIdType

)request.ParentFolderIds[0]).Id = Exchange.
DistinguishedFolderIdNameType

.calendar;

// Perform the FindItem request.

Exchange.

FindItemResponseType

response = binding.FindItem(request);

if

(response.ResponseMessages.Items[0].ResponseClass != Exchange.
ResponseClassType

.Success)
{

throw

new

Exception

(
“Unable to perform FindItem for an “

+
“associated Calendar Item.\r\n”

+
response.ResponseMessages.Items[0].ResponseCode.ToString() +
“\r\n”

+
response.ResponseMessages.Items[0].MessageText.ToString());
}
Exchange.

FindItemResponseMessageType

firmt = (Exchange.
FindItemResponseMessageType

)response.ResponseMessages.Items[0];

if

(firmt.RootFolder.TotalItemsInView != 1)
{

throw

new

Exception

(
“Find Item request failed, request returned “

+ firmt.RootFolder.TotalItemsInView +
” items.”

);
}
Exchange.

ArrayOfRealItemsType

itemArray = (Exchange.
ArrayOfRealItemsType

)firmt.RootFolder.Item;

return

itemArray.Items[0].ItemId;
}

…………………………………..

Hello,

It looks like you are consuming the Availability service (GetUserAvailability ) and want to use the ID returned on calendar events to call other methods in EWS. The right way to do this is to convert the ID you receive from GetUserAvailability to an EWS Id using the ConvertId method, instead of calling FindItem with a restriction. You can find more information about ConvertId here . Note that ConvertId is only available in Exchange SP1 and above.

David Claux | Program Manager – Exchange Web Services

David Claux –
, 29, 10:46 PM

Kim Brandl
, , 29, 11:19 PM

…………………………………..

Hello,

It looks like you are consuming the Availability service (GetUserAvailability ) and want to use the ID returned on calendar events to call other methods in EWS. The right way to do this is to convert the ID you receive from GetUserAvailability to an EWS Id using the ConvertId method, instead of calling FindItem with a restriction. You can find more information about ConvertId here . Note that ConvertId is only available in Exchange SP1 and above.

David Claux | Program Manager – Exchange Web Services

David Claux –
, 29, 10:46 PM

Kim Brandl
, , 29, 11:19 PM

…………………………………..

Hi David, and thanks for your answer.

The code that I posted is very old, It was running fine on labs servers for a year, so I didn’t take care about it.
A few days ago, we make some tests on production servers and …..

Today I’ve change all the convert code to ConvertId, and it’s converts ok,

But I don’t figure out how to remove the restriction and set the Id returned from ConvertId in the request.

I think that my brain is burned out
Can you help me please.

Thanks.

Luis

…………………………………..

Luis,

I am not sure I understand your question, but let me take a shot at answering it anyway.

By using ConvertId, you should have replaced all the code that you posted above. That is, instead of finding the calendar event using its store ID just to retrieve its EWS Id, you have directly converted the store ID into an EWS Id.

With that EWS Id, you can then retrieve the details of the calendar item, using the GetItem method.

Does this answer your question?

Also, just in case you missed it, we recently released the EWS Managed API beta which makes coding against EWS much easier than with auto-generated proxies.

David Claux | Program Manager – Exchange Web Services

David Claux –
, 30, 4:40 PM

…………………………………..

David, I change the whole thing, now is working.
I put the test code here, maybe it’s usefull for someone else.

Thank you so much to clarify my mind.

AlternateIdType

alternateItemId =
ExchangeUtils

.ConvertId(binding, mailBox, calendarEventDetailsId);

GetItemType

gitRequest =
new

GetItemType

();

ItemResponseShapeType

itemProperties =
new

ItemResponseShapeType

();

// Use the Default shape for the response.

itemProperties.BaseShape =

DefaultShapeNamesType

.IdOnly;
gitRequest.ItemShape = itemProperties;

BaseItemIdType

[] biItems =
new

BaseItemIdType

[1];

ItemIdType

itemIdType =
new

ItemIdType

();

itemIdType.Id = alternateItemId.Id;
biItems[0] = itemIdType;
gitRequest.ItemIds = biItems;

// Perform the inbox search

GetItemResponseType

response = binding.GetItem(gitRequest);

if

(response.ResponseMessages.Items[0].ResponseClass != Exchange.
ResponseClassType

.Success)
{

throw

new

Exception

(
“Unable to perform FindItem for an “

+
“associated Calendar Item.\r\n”

+
response.ResponseMessages.Items[0].ResponseCode.ToString() +
“\r\n”

+
response.ResponseMessages.Items[0].MessageText.ToString());
}

ArrayOfRealItemsType

itemArray = (
ArrayOfRealItemsType

)((
ItemInfoResponseMessageType

)response.ResponseMessages.Items[0]).Items;

if

(itemArray.Items.Length != 1)
{

throw

new

Exception

(
“Find Item request failed, request returned “

+ itemArray.Items.Length +
” items.”

);
}

return

itemArray.Items[0].ItemId;


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images