0
我的WebService:的CookieContainer和Web服務
public class Service1:WebService {
private readonly MNConnection _conn;
private MNLpu _lpu;
public Service1() {
_conn = new MNConnection();
}
[WebMethod(EnableSession = true)]
public void Open(string login, string password) {
_conn.Open(login, password);
_lpu = (MNLpu)_conn.CreateLPU();
}
[WebMethod(EnableSession = true)]
public decimal Get() {
return _lpu.Count;
}
}
當我把它從外部控制檯應用程序,它讓我在最後一行的NullReferenceException:
CookieContainer cookie = new CookieContainer();
Service1 lh = new Service1 {CookieContainer = cookie};
lh.Open("login", "pwd");
Console.WriteLine(lh.Get());
如果從Web服務中刪除Open()方法和插入到構造這樣的行它的工作正常:
_conn.Open(login, password);
_lpu = (MNLpu)_conn.CreateLPU();
如何解決它? P.S. MNConnection - 我自己的類,它適用於OracleConnection。