我有以下 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;
}