无法调用WCF函数
本文关键字:函数 WCF 调用 | 更新日期: 2023-09-27 18:10:23
我有一个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
在UI:
<client>
<endpoint address="http://localhost:49171/ExcelReader.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IExcelReader" contract="ExcelService.IExcelReader"
name="BasicHttpBinding_IExcelReader" />
</client>
运行应用程序时,wcf中的函数没有被调用。请帮助。
从Visual studio为IIS中的WCF服务创建一个虚拟目录。之后,从VS命令提示符调用WcfTestClient,并尝试将wcf服务引用添加到WcfTestClient(在我们的情况下,url可能是类似http://localhost/VirtualDirectoryName/ExcelReader.svc的东西)-如果服务和它的方法是可访问的,你可以从工具测试它-否则它会给你适当的错误