[已解决]无法使ObjectDataSource与WCF服务配合使用时遇到麻烦 [英] [Solved] Having trouble getting a ObjectDataSource to play nice with a WCF service

查看:80
本文介绍了[已解决]无法使ObjectDataSource与WCF服务配合使用时遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常烦人的新手问题.

我正在使用N层体系结构.我有一个DataEntity层和一个DataAccess层,然后有一个WCF服务,夹在数据实体层和基于ASP.NET网站的表示层之间.
我继续向WCF服务添加服务引用,然后执行以下ASP:

I am getting a really annoying newbie problem.

I am utilizing an N-tier architecture. I have a DataEntity layer and a DataAccess tier and then a WCF service sandwiched in between the data entity layer and the ASP.NET Web Site-based Presentation layer.

I went ahead and added a Service Reference to my WCF service and then I did the following ASP:

<form id="form1"  runat="server">
<div>
    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
        AutoGenerateColumns="False" >
        <columns>
            <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"
                SortExpression="Name" />
            <asp:BoundField DataField="email" HeaderText="email" ReadOnly="True"
                SortExpression="email" />
            <asp:BoundField DataField="phone" HeaderText="phone" ReadOnly="True"
                SortExpression="phone" />
            <asp:BoundField DataField="Zip" HeaderText="Zip" ReadOnly="True"
                SortExpression="Zip" />
            <asp:BoundField DataField="PropertyType" HeaderText="PropertyType"
                SortExpression="PropertyType" />
            <asp:BoundField DataField="Message" HeaderText="Message" ReadOnly="True"
                SortExpression="Message" />
            <asp:BoundField DataField="EntryDate" HeaderText="EntryDate"
                SortExpression="EntryDate" />
            <asp:BoundField DataField="URL" HeaderText="URL" ReadOnly="True"
                SortExpression="URL" />
            <asp:BoundField DataField="Form" HeaderText="Form" ReadOnly="True"
                SortExpression="Form" />
            <asp:BoundField DataField="CustomerNumber" HeaderText="CustomerNumber"
                SortExpression="CustomerNumber" />
            <asp:BoundField DataField="ContactType" HeaderText="ContactType"
                SortExpression="ContactType" />
        </columns>

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetConsultationRequestContacts"
        TypeName="DataServiceReference.DataServiceClient" />

</div>
</form>



我认为我做对了,但是我不断得到:

通信对象System.ServiceModel.ChannelFactory`1 [DataServiceReference.IDataService]不能用于通信,因为它处于Faulted状态.

我承认,我是新手.我还需要添加更多代码吗?

Brian



I think I''m doing it right, however I keep getting:

The communication object, System.ServiceModel.ChannelFactory`1[DataServiceReference.IDataService], cannot be used for communication because it is in the Faulted state.

I admit, I am a newbie. Is there more code I need to add?

Brian

推荐答案

我认为问题在于指定
TypeName ="DataServiceReference.DataServiceClient".将其指定为ProjectName.DataServiceReference,因为DataServiceClient是WCF自动创建的用于处理所有低级调用的类.
I think the problem is with specifying
TypeName="DataServiceReference.DataServiceClient". Specify it as Your ProjectName.DataServiceReference as DataServiceClient is the class created by WCF automatically for you to handle all low level calls.


我还发现您将要建立连接如下所示:

I also found that you''ll want to set up a connection to the adapter as follows:

using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    DataServiceReference.AbstractsClient _abstractsClient = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (_abstractsClient == null)
        {
            _abstractsClient = new DataServiceReference.AbstractsClient();
            _abstractsClient.Open();
        }
    }
    protected void AbstractsDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        // set the object instance
        if (_abstractsClient.State == System.ServiceModel.CommunicationState.Opened)
            e.ObjectInstance = _abstractsClient;
    }
    protected void AbstractsDataSource_ObjectDisposing(object sender, ObjectDataSourceDisposingEventArgs e)
    {
        // set this so the object is not disposed afterwards
        e.Cancel = true;
    }
    protected void AbstractsDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
    }
}


这篇关于[已解决]无法使ObjectDataSource与WCF服务配合使用时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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