开发者

Not able to invoke the WCF function

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 (开发者_StackOverflowException 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜