none
I can not load the service response during deploy,

    Question

  • Hey guys

    I have made an application following tutorial http://silverlight.net/learn/tutorials/sqldatagrid.aspx

    It works perfectly fine on development, debug mode and everything but when it is published, it gives following error

    throw new Error("Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()\n   at TestGrid.ServiceReference1.GetDataCompletedEventArgs.get_Result()\n   at TestGrid.Page.webService_GetDataCompleted(Object sender, GetDataCompletedEventArgs e)\n   at TestGrid.ServiceReference1.TestServiceClient.OnGetDataCompleted(Object state)");

    I have been trying for past 2 days and can't really find a good answer, and all I am trying to do is binding a grid and able to publish it.

    I've changed web.config and ServiceReferences.ClientConfig to direct it to the service, please help, all I am trying to do is bind a table and publish it on the web

    Peter

    Sunday, December 07, 2008 7:23 PM

Answers

All replies

  • Well, there are 3 things you have check, if you want your publish copy to work.

    1. Add a MyServiceHostFactory.cs where your ServiceReference1.svc is added

        public class MyServiceHostFactory : ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                Uri webServiceAddress = new Uri("http://mysite/ServiceReference1.svc");
                ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
                return webServiceHost;
            }
        }

    then add this to your .svc markup:

    Factory="<your namespace>.MyServiceHostFactory"

    You will find the namespace in your page.xaml above

    public partial class Page : UserControl{}

    2. After published extract the xap file and change the ServiceReferences.ClientConfig

    3. When the site is hosted, first check if your service is running or not by

    http://mysite/ServiceReference1.svc (sample)

    If it runs it will display some method and that means you have hosted it correctly in discountAsp or some hosting places.

    Hope this helps.

    and if this post was helpful then please 'Mark as Answer' - many thanks

    Sharker Khaleed Mahmud (MCPD)
    Software Developer

    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.

     

    Sunday, December 07, 2008 7:56 PM
  • I've added the Service Factory  and code is shown as below.

    namespace TestGrid
    {
        public class MyServiceHostFactory : ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                Uri webServiceAddress = new Uri("http://localhost/Test/TestService.svc");
                ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
                return webServiceHost;
            }
        }
    }

    after publishing it, i have  checked and service is there.

    i am still receiving the same error message.

    Monday, December 08, 2008 1:14 AM
  • I made some progress on my bug tracking,

    I am able to return a value if I don't use LINQ

    in the service file if i only have

        #region ITestService Members

        public List<test> GetData()
        {
           
            List<test> ret = new List<test>();
            test a = new test();
            a.FirstName="a";
            a.id = 1;
            a.LastName = "b";
            ret.Add(a);       
            return ret;
        
        }
        #endregion

    but the moment I try to use the linq session to pull data from data table it will give me above error

         #region ITestService Members

        public List<test> GetData()
        {
            TestingDataContext db = new TestingDataContext();
            var aret = (from testing in db.tests
                      orderby testing.id descending
                      select new test
                      {
                          id = testing.id,
                          FirstName = testing.FirstName,
                          LastName = testing.LastName
                      }).ToList().FirstOrDefault();
           
            List<test> ret = new List<test>();
            test a = new test();
            a.FirstName="a";
            a.id = 1;
            a.LastName = "b";
            ret.Add(a);
            return ret;
        }
        #endregion

     In this case I am not even adding the database's data into returned list, the error above will show....

    I guess there is some sort of permission issue with using LINQ inside webservice, I don't know how to fix it but this is as far as I got.

     I've gotten more progress, on Silverlight side I've put a catch exception around, ki9a from irc channel told me

    void webService_GetDataCompleted(object sender, TestGrid.ServiceReference1.GetDataCompletedEventArgs e)
            {
                //Initial Load
                try
                {
                    theDataGrid.ItemsSource = e.Result;
                }
                catch (Exception)
                {
                    HtmlPage.Window.Alert(e.Error.InnerException.Message);
                }
               
            }

     and I've gotten error: the remote server returned an error, NotFound

     since this works perfectly on debugginng mode, and it works with non linq data, my conclusion for it would be its not finding the data server through linq when its published.

     Peter

    Monday, December 08, 2008 2:59 AM
  • nvm, fixed it, connection string was set wrote

    Monday, December 08, 2008 12:11 PM