2011-10-05 71 views
0

我有一个asp.net应用程序,我的数据访问层是一个WCF服务。我使用VWD快递2010年在鸟瞰整个结构是这样的无法调用WCF功能

[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中的函数没有被调用。请帮助。

+0

你是否得到一些错误? –

+0

nopes ...我没有得到任何错误;( – Niranjan

+0

你在web.config中配置了什么?WCF需要指定它的端点 –

回答

0

从Visual Studio为IIS中的WCF服务创建一个虚拟目录。之后,从VS命令提示符处调用WcfTestClient,并尝试将WCc服务引用添加到WCFTestClient(URL中的URL可能类似于http://localhost/VirtualDirectoryName/ExcelReader.svc) - 如果服务及其方法可访问,则可以从工具 - 否则会给你适当的错误