0

以下の 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;

    }
4

2 に答える 2

2

通常、Web サービスはステートレスです。セッションを保存するには、HTTPContext を使用してセッションをキャッシュする必要があります。

于 2011-06-20T15:47:13.927 に答える
1

null オブジェクトがheaderof であることは間違いありませんreq.header。その行にブレーク ポイントを配置し、変数デバッガー ウィンドウで req.header の評価結果を確認します。本当に null の場合は、次のようなヘッダーを手動で追加する必要があります

req.headers = new Headers();
于 2011-06-20T15:48:56.423 に答える