操作期间发生异常,使结果无效. [英] An exception occurred during the operation,making the result invalid.

查看:97
本文介绍了操作期间发生异常,使结果无效.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过网格访问数据库时,我在客户端计算机上收到此错误.
我已经用简单的SQL数据库在localhost上托管了一个网站.当我尝试访问数据库时,它似乎工作正常.

代码:
clientconfig:

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:

<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>



Web服务:



Webservices:

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



page.xaml

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;
        }

    }
}

推荐答案

[ ^ ]线程可能会有所帮助
This[^] thread might help.


回答有关异常的答复:

这是从什么开始的建议.问题是您没有提供足够的有关异常的信息.请参阅我的指示:
我如何制作滚动条到达底部时将停止的循环 [当我运行应用程序时,异常是捕获了如何处理此问题? [如何在文件夹下创建事件日志 [ ^ ]

最后,如果您获得了所有异常信息,那么您就有更大的机会自己解决问题.如果不是,请参见Exceptions.Stack的转储.在调试配置中,您将看到源代码文件和行号.如果您的问题仍未解决,请发布您的代码,并在注释中注明与异常有关的相关代码行以及异常信息的重要部分.

这是基于真实材料而非猜测获得帮助的方法.

—SA
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


简单...您的端点不正确.
在您的计算机上它可以工作,因为端点是本地的
Simple... Your endpoint is incorrect.
On your computer it works because the endpoint is local
<endpoint address="http://localhost:52878/webService.svc" binding="customBinding"
               bindingConfiguration="CustomBinding_webService" contract="ServiceReference1.webService"
               name="CustomBinding_webService" />



您需要更新localhost:52878才能使其正常工作.



You''ll need to update the localhost:52878 to get this to work.


这篇关于操作期间发生异常,使结果无效.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆