2016-10-13 5 views
1

Imこれに続いてtutorial。私はWebApiを作成し、ブラウザからOKを実行します。しかし、Web参照として追加しようとすると、このエラーが表示されます。WebApiを作成しましたが、Web参照として追加できません

url http://localhost/WebApi/api/testのドキュメントが既知のドキュメントタイプとして認識されませんでした。 既知の各タイプのエラーメッセージが問題を解決するのに役立ちます。 - 'XMLスキーマ'からのレポートは 'ルートレベルのデータは無効です。ライン1、位置1 '。 - 'DISCOドキュメント' から報告書は「データ

TestController

namespace WebApi.Controllers 
{ 
    public class TestController : ApiController 
    { 
     public HttpResponseMessage Get() 
     { 
      return new HttpResponseMessage() 
      { 
       Content = new StringContent("GET: Test message") 
      }; 
     } 

     public HttpResponseMessage Post() 
     { 
      return new HttpResponseMessage() 
      { 
       Content = new StringContent("POST: Test message") 
      }; 
     } 

     public HttpResponseMessage Put() 
     { 
      return new HttpResponseMessage() 
      { 
       Content = new StringContent("PUT: Test message") 
      }; 
     } 
    } 
} 

ブラウザOKですが、エラーが表示されます。リンクでの回答に加えて

enter image description here

+1

http://stackoverflow.com/questions/18744407/why-cant-we-add-a-web-api-as-a-service-reference-in-以下 を参照してくださいサンプルコードビジュアル・スタジオ・ザ・イズ・ウェ – EJoshuaS

答えて

0

。 WebAPIコントローラにアクセスできる方法はたくさんあります。

  1. あなたは
  2. uは任意の.NETアプリケーションにASP.Net WebAPIのクライアントをインストールする場合、例えばHTTP要求を行い、カム任意のフレームワークをAngularJsなどのJavascript、アヤックスを使用して、クライアント側からアクセスすることができます。 (Console、WindowsFormなど)、HttpClient()をインスタンス化する前に参照を追加します。

    var client =new HttpClient(); 
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); 
    var result = client.GetAsync(new Uri("http://localhost:16665/api/myApiControllerName")).Result; 
    
関連する問題