0
是否可以通過添加方法類的dll來調用WCF服務中的外部方法?如何調用WCF服務項目中引用的外部DLL中的方法
我有一個現有的Web應用程序項目,方法getcabfare(**)
,現在我試圖創建一個新的WCF服務來訪問該getcabfare()
方法,方法是將該現有應用程序的引用添加到我的WCF項目中。
但我得到的錯誤
的NullReferenceException不能由用戶代碼來處理 - 對象引用 不設置到對象
的實例,這是我現有的項目「BasicCabApplication」這在商業邏輯層中有以下方法工作正常
namespace BasicCabApplication
{
public class BussinessLogic
{
public int getcabfare(string location)
{
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("Select fare from cablocations where area ='" + location +"'", con);
int fare = Convert.ToInt16(cmd.ExecuteScalar());
con.Close();
return fare;
}
}
這是我添加了上述項目的參考的我的wcf項目。和在Service1.svc.cs代碼低於
using BasicCabApplication;
namespace mywcftest1
{
public class Service1 : IService1
{
public int GetFare(string location)
{
BussinessLogic bl = new BussinessLogic();
int fare = bl.getcabfare(location);
return fare;
}
}
}
我得到的對象BL,但不能訪問該方法getcabfare(),其被拋出nullreference異常。
是不是可以訪問wcf項目(web服務)中的另一個項目的方法?或在我的代碼任何差錯....
歡迎來到堆棧溢出!幾乎所有的NullReferenceException都是一樣的。請參閱「[什麼是.NET中的NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)」的一些提示。 –