2011-06-20 12 views
0

以下の2つの方法があります。ログインメソッドはうまく動作し、セッショントークンを取得して設定します。 GetEvents()、GetEvents()のリクエストでsessionTokenを送信する必要があります。C#:Webサービスログインが動作していますが、別の方法でエラーが発生しています

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; 

    } 
+0

あなたのソースリンクは機能していません。 – therealmitchconnors

+0

ブラウザにコピーして貼り付けてください。.slnを.zipにダウンロードする必要があります – Anil

答えて

1

ヌルオブジェクトがheaderreq.headerであることを私は賭けたいと思います。その行にブレークポイントを置き、変数のデバッガウィンドウにreq.headerが何を評価するかを見てください。もし実際にヌルなら、手動でヘッダを追加する必要があります。

req.headers = new Headers(); 
+0

あなたの権利はreq.headerがnullです。新しいヘッダはどこから来たのですか?EDIT:上記の編集でエラーを修正しました。別のものがありました!、ありがとう!! – Anil

2

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