2011-10-05 74 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) - 如果服務及其方法可訪問,則可以從工具 - 否則會給你適當的錯誤