无法调用WCF函数

发布于 2024-12-08 09:28:39 字数 3590 浏览 1 评论 0原文

我有一个 asp .net 应用程序,我的数据访问层是 WCF 服务。我使用 VWD Express 2010。鸟瞰图的整个结构是这样的

    [ServiceContract]
    public interface IExcelReader
    {
       [OperationContract]
       [FaultContract(typeof(StaffAllocationFault))]        
       void ReadExcel();
    }


    public void ReadExcel()
    {
        DataSet dataCollection = new DataSet();

        table = new DataTable("Capacity");

        //gets the connection string for the excelsheet with the employee details
        //string strCon = ConfigurationManager.ConnectionStrings["capacityDB"].ConnectionString;
        string strCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\CapacityDB.xlsx;Extended Properties=Excel 12.0";

        //gets the predefined filters in the application
        string[] filter = GetDefinedFilters();

        //creates the connection object
        oledbCon = new OleDbConnection(strCon);

        try
        {
            //opens the connection object
            openConnection();

            string strCmd = "Select * from [Capacity Report Data$]";

            //creates the command object
            oledbCmd = new OleDbCommand(strCmd, oledbCon);

            //fills the datatable using the data adapter
            oledbAdapter = new OleDbDataAdapter();
            oledbAdapter.SelectCommand = oledbCmd;
            oledbAdapter.Fill(table);

            dataCollection.Tables.Add(table);

            //to trim off the trailing/preceding whitespaces
            foreach (DataRow row in table.Rows)
            {
                int count = 0;

                while (count < filter.Count())
                {
                    try
                    {
                        row[filter[count]] = row[filter[count]].ToString().Trim();

                        //if the field is blank
                        if (row[filter[count]].ToString() == "")
                            row[filter[count]] = "***";

                        count++;
                    }

                    catch (Exception ex)
                    {
                        throw new FaultException<StaffAllocationFault>(new StaffAllocationFault { FaultMessage = "Error while reading through the employee information" }, ex.Message);
                    }
                }
            }                
        }

        catch (Exception ex)
        {
            throw new FaultException<StaffAllocationFault>(new StaffAllocationFault { FaultMessage = "Error while retreiving employee information" }, ex.Message);
        }

        finally
        {
            //closes the oledb connection
            closeConnection();
        }
    }


    public void ReadFromExcel()
    {
        try
        {
            new ExcelReaderClient().ReadExcel();
        }
        //service specific exceptions
        catch (FaultException<StaffAllocationFault> ex)
        {
            throw new ExceptionLayer.StaffAllocationException("Error while reading from excel", ex);
        }
        //generic exceptions
        catch (Exception genEx)
        {
            throw genEx;
        }
    }

UI 中的我的 web.config

<client>
        <endpoint address="http://localhost:49171/ExcelReader.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IExcelReader" contract="ExcelService.IExcelReader"
            name="BasicHttpBinding_IExcelReader" />
    </client>

当我运行应用程序时,wcf 中的函数不是被调用。请帮忙。

I've an asp .net application, my Data Access Layer is a WCF service. I use VWD Express 2010. The whole structure in a bird's eye view is something like this

    [ServiceContract]
    public interface IExcelReader
    {
       [OperationContract]
       [FaultContract(typeof(StaffAllocationFault))]        
       void ReadExcel();
    }

    public void ReadExcel()
    {
        DataSet dataCollection = new DataSet();

        table = new DataTable("Capacity");

        //gets the connection string for the excelsheet with the employee details
        //string strCon = ConfigurationManager.ConnectionStrings["capacityDB"].ConnectionString;
        string strCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\CapacityDB.xlsx;Extended Properties=Excel 12.0";

        //gets the predefined filters in the application
        string[] filter = GetDefinedFilters();

        //creates the connection object
        oledbCon = new OleDbConnection(strCon);

        try
        {
            //opens the connection object
            openConnection();

            string strCmd = "Select * from [Capacity Report Data$]";

            //creates the command object
            oledbCmd = new OleDbCommand(strCmd, oledbCon);

            //fills the datatable using the data adapter
            oledbAdapter = new OleDbDataAdapter();
            oledbAdapter.SelectCommand = oledbCmd;
            oledbAdapter.Fill(table);

            dataCollection.Tables.Add(table);

            //to trim off the trailing/preceding whitespaces
            foreach (DataRow row in table.Rows)
            {
                int count = 0;

                while (count < filter.Count())
                {
                    try
                    {
                        row[filter[count]] = row[filter[count]].ToString().Trim();

                        //if the field is blank
                        if (row[filter[count]].ToString() == "")
                            row[filter[count]] = "***";

                        count++;
                    }

                    catch (Exception ex)
                    {
                        throw new FaultException<StaffAllocationFault>(new StaffAllocationFault { FaultMessage = "Error while reading through the employee information" }, ex.Message);
                    }
                }
            }                
        }

        catch (Exception ex)
        {
            throw new FaultException<StaffAllocationFault>(new StaffAllocationFault { FaultMessage = "Error while retreiving employee information" }, ex.Message);
        }

        finally
        {
            //closes the oledb connection
            closeConnection();
        }
    }

    public void ReadFromExcel()
    {
        try
        {
            new ExcelReaderClient().ReadExcel();
        }
        //service specific exceptions
        catch (FaultException<StaffAllocationFault> ex)
        {
            throw new ExceptionLayer.StaffAllocationException("Error while reading from excel", ex);
        }
        //generic exceptions
        catch (Exception genEx)
        {
            throw genEx;
        }
    }

My web.config in UI:

<client>
        <endpoint address="http://localhost:49171/ExcelReader.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IExcelReader" contract="ExcelService.IExcelReader"
            name="BasicHttpBinding_IExcelReader" />
    </client>

when I run the application the function in the wcf is not getting invoked. Pls help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2024-12-15 09:28:39

从 Visual Studio 中为 IIS 中的 WCF 服务创建虚拟目录。之后从 VS 命令提示符调用 WcfTestClient,并尝试将 wcf 服务引用添加到 WCFTestClient(您的情况下的 url 可能类似于 http://localhost/VirtualDirectoryName/ExcelReader.svc) - 如果服务及其方法可访问,您可以从工具测试它 - 否则它会给您相应的错误

Create a virtual directory for the WCF service in IIS from the Visual studio. After that invoke the WcfTestClient from the VS command prompt, and try to add the wcf service reference to the WCFTestClient (the url in ur case might be something like http://localhost/VirtualDirectoryName/ExcelReader.svc) - If the Service and its methods are accessible you can test it from tool - otherwise it will give you appropriate errors

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文