我有一个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;
}
}
用户界面中的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)
从Visual Studio中为IIS中的WCF服务创建虚拟目录。之后从VS命令提示符调用WcfTestClient,并尝试将wcf服务引用添加到WCFTestClient(在大小写的情况下,url可能类似于http://localhost/VirtualDirectoryName/ExcelReader.svc) - 如果可以访问服务及其方法,则可以测试它来自工具 - 否则会给你适当的错误