我有一个创建约会的Silverlight应用程序,但由于它未标记为“已安排”,因此它不会显示在日历中。我正在使用SOAP服务,这里是一些示例代码,它在按钮点击时触发,创建约会但它没有显示在日历中:
TestCommand = new RelayCommand(() =>
{
var soapCtx = ServiceHelper.GetSingletonSoapService();
var activityId = Guid.NewGuid();
var appt = new Entity()
{
Id = activityId,
LogicalName = "appointment"
};
appt["activityid"] = activityId;
appt["scheduledstart"] = DateTime.Now.Date;
appt["scheduledend"] = DateTime.Now.Date.AddHours(1);
appt["description"] = "Test 1 2 3";
appt["subject"] = "Test Command Button Appointment";
appt["location"] = "Location 1 2 3";
soapCtx.BeginCreate(appt, ar =>
{
var response = soapCtx.EndCreate(ar);
var bookRequest = new OrganizationRequest();
bookRequest.RequestName = "Book";
bookRequest["Target"] = appt;
soapCtx.BeginExecute(bookRequest,
new AsyncCallback(OnBookRequestedCompleted), soapCtx);
}, null);
});
void OnBookRequestedCompleted(IAsyncResult ar)
{
var soapCtx = (IOrganizationService)ar.AsyncState;
var response = soapCtx.EndExecute(ar);
}
我一直在OnBookRequestedCompleted方法中获得“NotFound”异常。有没有不同的方法呢?
答案 0 :(得分:1)
使用Fiddler调试您的HTTP请求/响应,这将为您提供有关“未找到”异常的详细信息。
答案 1 :(得分:0)
您不应该设置BookRequest返回的ActivityId字段。如果BookResponse.ValidationResult.ValidationSuccess == true,则apptId = BookResponse.ValidationResult.ActivityId
您需要使用BookRequest返回的ID调用SetStateRequest,以将状态设置为Scheduled
例如:
SetStateRequest state = new SetStateRequest();
state.State = new OptionSetValue(3); // Scheduled
state.Status = new OptionSetValue(5); // Busy
state.EntityMoniker = new EntityReference("appointment", apptId);
SetStateResponse stateSet = (SetStateResponse)this.orgService.Execute(state);