2011-07-08 13 views
3

webservicesへの接続については、次のコードを記述しました。コードの上に使用してWindows Phone 7でwebserviceメソッドを呼び出す方法は?

WebClient wc = new WebClient(); 
wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx")); 
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted); 

void wc_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e) 
{ 
    Debug.WriteLine("Web service says: " + e.Result); 
    using (var reader = new StringReader(e.Result)) 
    { 
     String str = reader.ReadToEnd(); 
    } 
} 

iがHTMLVisulaizerで結果を取得したいresult.But文字列を取得し、その後、私は簡単に特定のメソッドにアクセスすることができますwebservice.thenことを持つ方法が何であるかを知っています。 Windows phone 7でWebサービスメソッドを呼び出す方法を教えてください。webserviceで私は5つのwebmethods.howを取得して、特定のwebmenthodを呼び出す方法を持っています。

私に事前に感謝を教えてください。

+1

可能重複?私はdid.Fo](http://stackoverflow.com/questions/6620194/how-to-connect-xml-web-services-in-windows-phone-7) –

答えて

2

@Jasonジェームズ

最初のステップは:ジェイソン・ジェームズは非常に詳細な指示を持っているよう

あなたは、参照先のサービスを追加する必要があります。

ステップ2:

あなたはApp.xaml.csを開くことができ、機能に

public Apps() 
{ 
    // Global handler for uncaught exceptions. 
      UnhandledException += Application_UnhandledException; 

      // Show graphics profiling information while debugging. 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // Display the current frame rate counters. 
       Application.Current.Host.Settings.EnableFrameRateCounter = true; 

       // Show the areas of the app that are being redrawn in each frame. 
       //Application.Current.Host.Settings.EnableRedrawRegions = true; 

       // Enable non-production analysis visualization mode, 
       // which shows areas of a page that are being GPU accelerated with a colored overlay. 
       //Application.Current.Host.Settings.EnableCacheVisualization = true; 
      } 
      // You can declare objects here that you will use 
      //Examlpe: NameservicesReferent.(Function that returns services) = new NameservicesReferent.(Function that returns services)(); 

Ws_Function =新しいNameservices.ServiceSoapClientを()Appsに。

} 

ステップ3:Mainpage.xaml.cs

GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted += new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted); 
GlobalVariables.***NameWedservise***.getLinkAdvertiseIndexAsync("**parameters to be passed**"); 

ステップ4:

void Ws_advertise_getLinkAdvertiseIndexCompleted(object sender, advertise.getLinkAdvertiseIndexCompletedEventArgs e) 
     { 
      //function returns the results to you, the example here is an array 
      string[] array = null; 
      try 

      { 
       array = e.result; 
       if(array != null) 

      } 
      cath(exception ex) 
      { 

      } 
      finally 
      { 
      array = null; 
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted -= new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted); 
      } 
     } 
のWindows Phone 7でXML Webサービスを接続する方法[の
5

@venkateswaraは、あなたはどの1あなたのコードで呼び出すために知っているので、既知のWebReferenceメソッドのリストを取得について話していますか? WPReプロジェクトにWebReferenceを追加するときに、この既知のメソッド呼び出しのこれが表示されませんか?あなたがVSでWP7アプリを開発しているので、私はあなたがこれをしたい理由を見ることができません。自分でWebサービスを所有していなくても、プロジェクトへの参照を追加するにはVSから接続する必要があります。以下

WebReferenceが追加されたVS2010の画面です。 操作が右側にリストされています。

enter image description here

は一度使用すると、メソッドが呼び出されるべきかを理解するためにObjectBrowserを使用することができます追加しました。

私はあなたの質問から何かを見逃している場合は私に知らせてください。

+0

こんにちはJasonthe同じ手順R iは、オブジェクトエクスプローラでその方法を見つけることができませんでしたが、reference.theメソッド名が「Genericmethod()」で追加しているとき、私はその方法を見ましたが、オブジェクトエクスプローラで、私は「GenericWebMethodAsyncは()」私は私を見つけることができませんでした見たメソッドを呼び出しますメソッド "Genericmethod()"をオブジェクトエクスプローラで返します。データセットを返します。何が間違っているのか教えてください。 – Sravanti

+1

WP7では、メソッドを非同期に呼び出すことができ、参照を追加するときに生成されるプロキシは非同期呼び出しのみを作成すると考えています。そのため、オブジェクトブラウザではxxxxxAsync()メソッドのみが表示されます。希望が役立ちます。 –

関連する問題