Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I am getting this error on client computer while trying to access database through grid.
I have hosted an website on localhost with simple SQL database. and when i try to access database it seems to be working fine.

CODE:
clientconfig:

XML
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_webService">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:52878/webService.svc" binding="customBinding"
                bindingConfiguration="CustomBinding_webService" contract="ServiceReference1.webService"
                name="CustomBinding_webService" />
        </client>
    </system.serviceModel>
</configuration>


Webservices:
MSIL
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;

using System.ServiceModel.DomainServices;

namespace Website.Web
{
    [ServiceContract(Namespace = "")]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true, AddressFilterMode = AddressFilterMode.Any)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class webService
    {


          [OperationContract]

        public List<Data> GetRows()
        {
           DatabaseDataContext db = new DatabaseDataContext();
            var selected_rows = from rows in db.Datas select rows;
           return selected_rows.ToList();

        }

        [OperationContract]

        public void InsertData(string n1, string n2, string n3)
        {

            DatabaseDataContext db = new DatabaseDataContext();
            Data row = new Data
            {
                Key = Guid.NewGuid(),
                Alpha = n1,
                Beta = n2,
                Gamma = n3
            };

            db.Datas.InsertOnSubmit(row);
            db.SubmitChanges();
        }



        // Add more operations here and mark them with [OperationContract]
    }
}


page.xaml

XML
namespace Website
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using Website.ServiceReference1;
    using System.Data;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Home : Page
    {
        /// <summary>
        /// Creates a new <see cref="Home"/> instance.
        /// </summary>
        public Home()
        {
            InitializeComponent();

            this.Title = ApplicationStrings.HomePageTitle;
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void Submit_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            webServiceClient webclinet = new webServiceClient();
            webclinet.InsertDataAsync(textBox1.Text, textBox2.Text, textBox3.Text);

        }

        private void Get_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            webServiceClient webclinet = new webServiceClient();

            webclinet.GetRowsAsync();
            webclinet.GetRowsCompleted += new System.EventHandler<GetRowsCompletedEventArgs>(webclinet_GetRowsCompleted);
           webclinet.GetRowsAsync();

        }
        void webclinet_GetRowsCompleted(object sender, GetRowsCompletedEventArgs e)
        {
            Grid1.ItemsSource = e.Result;
        }

    }
}
Posted
Comments
Sergey Alexandrovich Kryukov 14-Mar-11 15:44pm    
No explanation of the "error". Still hoping for an answer?
--SA
mohit`12 15-Mar-11 13:09pm    
An Exception occurred during the operation, making the result invalid. Check InnerException for exception details. I am getting this error when i try to access my website database from client computer but when i use website database from host machine it doesnot throw this error.
William Winner 14-Mar-11 16:32pm    
You are getting what error??? We can't help you unless you tell us what error you're getting.

This[^] thread might help.
 
Share this answer
 
Comments
mohit`12 15-Mar-11 13:09pm    
thx i will look in to it.(:
Answering to the reply about exception:

Here is the advice what to start with. The problem is that you don't provide enough information about exception. Please see my directions:
How do i make a loop that will stop when a scrollbar reaches the bottom[^]
When i run an application an exception is caught how to handle this?[^]
(Sorry, many items are related to UI. Pay attention to what's applicable to your case.)

Additionally, in Web Service (if exception is there), you should use system even log. Here is some advanced code sample:
How to create event log under a folder[^]

And finally, if you get all exception information, you have a better chance to resolve the problem yourself. If not, see the dump of Exceptions.Stack. In Debug configuration, you will see source code files and line number. If your problem is not solved yet, post your code with the relevant code lines commented as involved in the exception as well as important part of exception information.

This is the way to get help based on real material, not guesswork.

—SA
 
Share this answer
 
Simple... Your endpoint is incorrect.
On your computer it works because the endpoint is local
CSS
<endpoint address="http://localhost:52878/webService.svc" binding="customBinding"
               bindingConfiguration="CustomBinding_webService" contract="ServiceReference1.webService"
               name="CustomBinding_webService" />


You'll need to update the localhost:52878 to get this to work.
 
Share this answer
 
v2
Comments
Espen Harlinn 15-Mar-11 19:00pm    
Nice, my 5
mohit`12 16-Mar-11 15:04pm    
i already changed my endpoint to localhost/Web1/webService.svc since it's hosted from IIS and it's under Web1
Markus is definitely on to something - that binding will not work for deployment.

I'd also wrap the Grid1.ItemsSource = e.Result; in a try/catch block, like:
void webclinet_GetRowsCompleted(object sender, GetRowsCompletedEventArgs e)        
{
 try
 {
  webclinet.GetRowsCompleted -= webclinet_GetRowsCompleted; // Request completed, remove handler 
  if(e.Error != null)
  {
   // Do something to display e.Error exception
  }
  Grid1.ItemsSource = e.Result;
 }
 catch(Exception exc)
 {
   // Do something to display exception   
 }
}


Best regards
Espen Harlinn
 
Share this answer
 
Comments
mohit`12 16-Mar-11 11:57am    
okay the problem is i am not able to get result WHEN i try to access my website from client computer so i will not be able to track down my exact error neither can use breakpoint everything is working fine in local computer. although i will try try/catch block if it can tell me what exact error is.
Espen Harlinn 16-Mar-11 13:36pm    
Take a look at http://msdn.microsoft.com/en-us/library/cc197940(v=vs.95).aspx, and read the section on "Additional Considerations When Creating Services"

If you host your SilverLight application in a web page on an IIS server on the standard port - 80, you probably need to use a clientaccesspolicy.xml file to allow cross-domain access.
see http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx for more information.

Good luck :)
mohit`12 16-Mar-11 13:49pm    
thanks a lot and yes i do have clientaccesspolicy.xml and cross-domain access ..
Espen Harlinn 16-Mar-11 15:08pm    
At this point I'd try creating a very simple regular .Net client - and use it to check that the service is accessible, and that you are not having firewall problems ...
mohit`12 18-Mar-11 8:57am    
i already tried that i am able to run service and also able to access website from client computer the main problem comes when i try to modify database maybe there is some permission problem or i am missing something that would be great if you can provide me some kind of code example of make a small project of web project which can be deployed on LAN.

thanks for your time regards,
M

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900