locked
SearchRequest is not available when working with silverlight and CRM 2011 SOAP Service? RRS feed

  • Question

  • Hi, i am pretyy new to CRM 2011 and Silverlight development. what i want to achieve is to fetch all the available time slots for particular resources,Sites for an appointment to set. Now I bing about this and found MS CRM 2011 sdk comes with the sample code very much similar to this(~\sdk\samplecode\cs\businessdatamodel\scheduleandappointment). I followed the same thing with the silverlight application and able to create the appointment object as it was available  due to the organization service reference was added. But when i want to create the Object of SearchRequest And SearchResponse classes they are not available with the service reference, which is available in sdk sample code.

    So, my question is, is there is a different way to query the available time slots for resource,Sites with silverlight application Consuming organization service SOAP end points?

    Please guide me, as i am stuck with this issue for more than 2 days.

    Monday, September 23, 2013 6:24 AM

Answers

  • Hi Kalimk,

    Thanks for your reply.

    But i am not using any library but only adding Organization service reference to my silverlight application.I

    I bing about this and i found that there is not any class like SearchRequest and SearchResponse when working with the SOAP end points. Instead i have to use OrganizationRequest and OrganizationResponse for that.

    following are my functions

    private void PrepareApointmentRequest()
            {
                try
                {
                    AppointmentRequest appointmentReq = new AppointmentRequest
                    {
                        RequiredResources = ResourceOnActivity,
                        Direction = SearchDirection.Backward,
                        Duration = 240,
                        NumberOfResults = 100,
                        ServiceId = new Guid("458976704-0722-e311-a378-000c29015f60"),
                        // The search window describes the time when the resouce can be scheduled.
                        // It must be set.
                        SearchWindowStart = DateTime.Now.ToUniversalTime(),
                        SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
                        UserTimeZoneCode = 1
                    };
                    OrganizationRequest req = new OrganizationRequest() { RequestName = "Search" };
                    req["AppointmentRequest"] = appointmentReq;

                    crmService.BeginExecute(req,OnFatchAvailibillityComplete, crmService);
                }
                catch (Exception ex)
                {

                    _syncContext.Send(ShowError, ex);
                    return;
                }
                

                //crmService.BeginExecute(appointmentReq, OnFatchAvailibillityComplete, crmService);
                // Verify that the resources have been scheduled                
                //SearchRequest search = new SearchRequest
                //{
                //    AppointmentRequest = appointmentReq
                //};
                //SearchResponse searched = (SearchResponse)crmService.BeginExecute(search);

                //if (searched.SearchResults.Proposals.Length > 0)
                //{
                //    Console.WriteLine("Scheduled the resources sucessfully.");
                //}
                
                
            }
            private void OnFatchAvailibillityComplete(IAsyncResult result)
            {
                try
                {
                    OrganizationResponse resp = ((IOrganizationService)result.AsyncState).EndExecute(result);

                    SearchResults results = (SearchResults)resp["SearchResults"];

                   // this.Dispatcher.BeginInvoke(() => ProcessAppointments(results));

                }
                catch (Exception ex)
                {
                    _syncContext.Send(ShowError, ex);
                    return;
                }
            }

    The problem is different now i am getting error at the line which is underlined in my code in function "OnFatchAvailibillityComplete". And the error is "The remote server returned an error: NotFound."

    Am i trying to access some entity which is not present in CRM? Can you please point me what i might be doing wrong in my code?

    Monday, September 23, 2013 8:39 AM
  • Hi Kamlik,

    Thank you very much for your time.

    I have solved the problem stated above. The problem was i was passing the RequiredResource obeservable collection to the appointmentrequest object after replacing it with new ObservableCollection<RequiredResource>() the error is gone. And i am getting the expected result, i don't know the reason behind this, though it works perfect for me.

    Monday, September 23, 2013 9:31 AM

All replies

  • Hi Manish,

    The Soap library doesn't have BeginExecuteSearchRequest and AppointmentRequest . Refer below blog for more information.

    http://mscrmblogger.com/2011/06/15/searchrequest/

    Hope this helps!

    Thanks!

    Monday, September 23, 2013 7:02 AM
  • Hi Kalimk,

    Thanks for your reply.

    But i am not using any library but only adding Organization service reference to my silverlight application.I

    I bing about this and i found that there is not any class like SearchRequest and SearchResponse when working with the SOAP end points. Instead i have to use OrganizationRequest and OrganizationResponse for that.

    following are my functions

    private void PrepareApointmentRequest()
            {
                try
                {
                    AppointmentRequest appointmentReq = new AppointmentRequest
                    {
                        RequiredResources = ResourceOnActivity,
                        Direction = SearchDirection.Backward,
                        Duration = 240,
                        NumberOfResults = 100,
                        ServiceId = new Guid("458976704-0722-e311-a378-000c29015f60"),
                        // The search window describes the time when the resouce can be scheduled.
                        // It must be set.
                        SearchWindowStart = DateTime.Now.ToUniversalTime(),
                        SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
                        UserTimeZoneCode = 1
                    };
                    OrganizationRequest req = new OrganizationRequest() { RequestName = "Search" };
                    req["AppointmentRequest"] = appointmentReq;

                    crmService.BeginExecute(req,OnFatchAvailibillityComplete, crmService);
                }
                catch (Exception ex)
                {

                    _syncContext.Send(ShowError, ex);
                    return;
                }
                

                //crmService.BeginExecute(appointmentReq, OnFatchAvailibillityComplete, crmService);
                // Verify that the resources have been scheduled                
                //SearchRequest search = new SearchRequest
                //{
                //    AppointmentRequest = appointmentReq
                //};
                //SearchResponse searched = (SearchResponse)crmService.BeginExecute(search);

                //if (searched.SearchResults.Proposals.Length > 0)
                //{
                //    Console.WriteLine("Scheduled the resources sucessfully.");
                //}
                
                
            }
            private void OnFatchAvailibillityComplete(IAsyncResult result)
            {
                try
                {
                    OrganizationResponse resp = ((IOrganizationService)result.AsyncState).EndExecute(result);

                    SearchResults results = (SearchResults)resp["SearchResults"];

                   // this.Dispatcher.BeginInvoke(() => ProcessAppointments(results));

                }
                catch (Exception ex)
                {
                    _syncContext.Send(ShowError, ex);
                    return;
                }
            }

    The problem is different now i am getting error at the line which is underlined in my code in function "OnFatchAvailibillityComplete". And the error is "The remote server returned an error: NotFound."

    Am i trying to access some entity which is not present in CRM? Can you please point me what i might be doing wrong in my code?

    Monday, September 23, 2013 8:39 AM
  • Hi Kamlik,

    Thank you very much for your time.

    I have solved the problem stated above. The problem was i was passing the RequiredResource obeservable collection to the appointmentrequest object after replacing it with new ObservableCollection<RequiredResource>() the error is gone. And i am getting the expected result, i don't know the reason behind this, though it works perfect for me.

    Monday, September 23, 2013 9:31 AM
  • Hi Manish,

    Glad to hear that it worked. Would you please close this forum so that others would get the help?

    Thanks!

    Monday, September 23, 2013 9:48 AM