以下の 2 つのメソッドがクラスにあり、ログイン メソッドは正常に動作し、セッション トークンを取得して設定しますが、GetEvents() を使用するには、GetEvents() のリクエストで sessionToken を送信する必要があります。
しかし、getEvents() のコードの 4 行目 (コメントと空白を除く) で、エラーが発生します: オブジェクト参照がオブジェクトのインスタンスに設定されていません。
The Entire Source can be downloaded here: (Copy and Paste into your browser)
http://www.theebookzone.co.uk/betfairui.zip
私が間違っていることはありますか?
この問題に直接関係していなくても、助けていただければ幸いです。
public static string SessionToken = ""; // Set by Login();
static LoginResp Login()
{
// Make a new BFGS instance
BFGlobal = new BFGlobalService.BFGlobalService();
// Set up the request in [req]
LoginReq req = new LoginReq();
req.username = username;
req.password = password;
req.productId = productId;
req.vendorSoftwareId = softwareId;
// Set up the response in [resp]
// Execute the call, and pass in the request
LoginResp resp = BFGlobal.login(req);
// Sets our public variable above to the recieved sessionToken
SessionToken = resp.header.sessionToken;
// return [resp] - which is the response from the call
return resp;
}
public Array GetEvents()
{
// This will set the sessionToken declared at the top.
LoginToBetfair();
// Make a new instance of the web service
BFGlobal = new BFGlobalService.BFGlobalService();
// Load up the request
GetEventsReq req = new GetEventsReq();
// Error Line Below:
req.header.sessionToken = SessionToken; // <--- Here is where I get the error
// Error Above Line: Object reference not set to an instance of an object.
GetEventsResp resp = BFGlobal.getEvents(req);
Array marketItems = resp.marketItems;
return marketItems;
}