2017-11-28 6 views
0

私は2つのプロジェクトを作成して、Webサービスをテストしています。AMSX Webサービス

プロジェクトの一つは、第二のプロジェクトがメインであるASMX

namespace KioskWS 
    { 
     /// <summary> 
     /// Summary description for WebService 
     /// </summary> 
     [WebService(Namespace = "http://localhost/KioskWS/WebService.asmx")] 
     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
     [System.ComponentModel.ToolboxItem(false)] 
     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     // [System.Web.Script.Services.ScriptService] 
     public class WebService : System.Web.Services.WebService 
     { 
      [WebMethod] 
      public string HelloWorld() 
      { 
       return "Hello World"; 
      } 
     } 
    } 

です。 Universal Windowsを使用しており、Add Web Referenceはありません。テストするメッセージボックスにhello worldを表示するためにWebサービスを呼び出すにはどうすればよいですか?以下のコードは動作しません。助けてください!

public MainPage() 
     { 
      this.InitializeComponent(); 

      KioskWS.HelloWorldResponse ws = new KioskWS.HelloWorldResponse(); 
      string message = ws.ToString(); 
      MessageDialog clickMessage = new MessageDialog(message); 
      clickMessage.ShowAsync(); 

     } 
+0

https://stackoverflow.com/questions/40743255/universal-windows-platform-consuming-web-service-asmx-content-type-parsingの複製と思われます –

+0

ところで....これはWindows 8です.x普遍的なアプリ?またはWindows 10の普遍的なアプリですか?どのsdkをターゲティングしていますか? –

+0

Windows 10ユニバーサルアプリケーション。今すぐWebサービスをテストしようとしていますが、メッセージボックスにHello Worldを取得できません – Syy

答えて

0

私はしばらくASMXを使用していないが、この必要があります。

KioskWS.HelloWorldResponse ws = new KioskWS.HelloWorldResponse(); 
string message = ws.ToString(); 

このようなものではない:

KioskWS.WebService ws = new KioskWS.WebService(); 
string message = ws.HelloWorld(); 

おそらくASMX側のWebServiceクラスの名前を変更読みやすく理解しやすくしています。

+0

名前空間に型または名前空間の名前が存在しません(アセンブリ参照がありませんか?) – Syy

+0

最初のものが使用できますメッセージボックスにKioskWS.HelloWordResponseが表示されます – Syy

0

ユニバーサルWindowsを使用しており、[Web参照の追加]はありません。

UWPアプリケーションで「サービス参照を追加する」必要があります。 UWPプロジェクトを右クリックし、[サービス参照の追加]を選択します。 現在のソリューションのWebサービスを検出し、参照するWebサービスを選択し、名前空間名を指定します(例:KioskWS)。

enter image description here

そして、あなたはUWPアプリでWebサービスを呼び出すことができます。例えば、HellowWorldを起動し、好きなはずです本文テキストは次の示しています

private async void Page_Loaded(object sender, RoutedEventArgs e) 
{ 
    KioskWS.WebServiceSoapClient client = new KioskWS.WebServiceSoapClient(); 
    HelloWorldResponse test = await client.HelloWorldAsync(); 
    string message = test.Body.HelloWorldResult; 
    MessageDialog clickMessage = new MessageDialog(message); 
    await clickMessage.ShowAsync(); 
} 

はまた、私はあなたの代わりに、「ASP.NET Webサービス」(通称ASMX)以来、WCFサービスを使用することをお勧めすることは、従来の技術です。詳細はthis threadを参照してください。