2016-09-14 8 views
0

ローカルホストを呼び出すときに起動するWebサービスを作成するための3つの技術的な質問がありました。たとえば、localhost/whateverやlocalhostと入力すればメッセージが返されるはずです。エンドポイントをWebサービスにリッスンする方法を教えてください。

たとえば、localhostエンドポイントなどのWebサービスをリスンするエンドポイントを取得するにはどうすればよいですか?言い換えれば、書かれたWebサービスにどのようにWebページを関連付けるのですか?

私はMSのVisual Studio内からクロムを実行しようとすると、私は次のエラーを取得する:続い

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

:ここ

Error: Cannot obtain Metadata from Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at Metadata contains a reference that cannot be resolved: ''. There was no endpoint listening at that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found.HTTP GET Error
URI: The HTML document does not contain Web service discovery information.

はそれがあるならば、私のサービスコードは、WebConfigのファイルが続いています助けてください。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Activation; 
using System.ServiceModel.Web; 
using System.Text; 

namespace MyNameIsTwitter 
{ 
    [ServiceContract(Namespace = "http://localhost/")] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class Service1 
    { 
     // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json) 
     // To create an operation that returns XML, 
     //  add [WebGet(ResponseFormat=WebMessageFormat.Xml)], 
     //  and include the following line in the operation body: 
     //   WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; 
     [OperationContract] 
     public string DoWork() 
     { 
      // Add your operation implementation here 
      int error = 0; 
      string url = HttpContext.Current.Request.Url.AbsoluteUri; 
      // http://localhost:1302/TESTERS/Default6.aspx 

      string path = HttpContext.Current.Request.Url.AbsolutePath; 
      // /TESTERS/Default6.aspx 

      string host = HttpContext.Current.Request.Url.Host; 
      // localhost 

      switch (host) 
      { 
       case "//localhost": switch (path) 
            { 
             case "": error = 1; 
               break; 
             default: break; 
            } 
            break; 
       default: break; 
      } 
      if (error == 1) 
      { 
       return "Try /hello/:name"; 
      } 
      else 
      { 
       return "worked"; 
      } 
     } 

     // Add more operations here and mark them with [OperationContract] 
    } 
} 

web.configファイル

<?xml version="1.0"?> 

    <!-- 
     For more information on how to configure your ASP.NET application, please visit 
     http://go.microsoft.com/fwlink/?LinkId=169433 
     --> 

    <configuration> 
     <system.web> 
      <compilation debug="true" targetFramework="4.5" /> 
      <httpRuntime targetFramework="4.5" /> 
     </system.web> 

     <system.serviceModel> 
      <behaviors> 
       <endpointBehaviors> 
        <behavior name="MyNameIsTwitter.Service1AspNetAjaxBehavior"> 
         <enableWebScript /> 
        </behavior> 
       </endpointBehaviors> 
      </behaviors> 
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
       multipleSiteBindingsEnabled="true" /> 
      <services> 
       <service name="MyNameIsTwitter.Service1"> 
       <endpoint address="localhost/" behaviorConfiguration="MyNameIsTwitter.Service1AspNetAjaxBehavior" 
        binding="webHttpBinding" contract="MyNameIsTwitter.Service1" /> 
       </service> 
      </services> 
     </system.serviceModel> 
    </configuration> 

答えて

0

あなたはMEXを理解する必要があるでしょう:

そして、あなたの404エラーに関するTry this。ローカルIIS上でWebサービスを実行する必要があります。

+0

この素敵な記事を共有してくれてありがとうございます。記事がWeb設定ファイルで私に伝えていることを実装した後、正しい方向に進んでいるようです。http:// localhost:63622 /今、私は取得しています。 HTTPエラー403.14 - 禁止 Webサーバーは、このディレクトリの内容を一覧表示しないように構成されています。私はこれが私のラップトップ上のIISの設定と関係があると思いますが、残念ながら私はこれを修正する手助けをするまであなたに完全なマークを与えることはできません。なぜ人々は人生をさらに複雑にするのですか?それは –

+0

IISの設定の問題であってはならず、認証モードが正しく設定されていないか、デフォルトページが利用できないなどの理由が複数ある可能性があります。この問題を解決するもう1つの方法は、Webサービスを提供するVisual Studioの別のインスタンスを実行し、そのURLをアプリケーションで使用することです。 – Mike

+0

あなたは正しいマイクだと思います。マイクロソフトは、Windows 10オペレーティングシステムに含まれているiisを適切にサポートしていません。このラップトップでは、Windows 7からWindows 10にアップグレードしていて、Microsoftのドキュメントに従ってinetmanager.exeを見つけることさえできません。私は今、電話でマイクロソフトの男と話して、iis 10をダウンロードしようとしています。これは適切なバージョンです。うまくいけば、私はこのHTTPエラー403.14を修正するのに役立つinetmanagerが含まれます。私が気づいているのは、主にマイクロソフトの優れたサポートの欠如です。彼らはあなたに水っぽい製品を販売したいと思うようです。 –

関連する問題