質問

HTTP Getを使用して非常にシンプルなWCFサービスを使用しようとしましたが、機能することはできません。私たちはそれらの「ガイド」に従っていますが、それは機能しません

次のURLでサービスを呼び出すと、エラーが見つからないページが表示されます。

http:// localhost:9999/service1.svc/getData/ABC

ベースURL(http:// localhost:9999/service1.svc)は正常に動作し、WCFサービス情報ページを正しく返します。

これらは、例を再現するための手順とコードです。

  1. Visual Studio 2010で、新しい「WCFサービスアプリケーション」プロジェクトを作成します
  2. iServiceインターフェイスをこのコードに置き換えます

      [ServiceContract()]
      public interface IService1
      {
          [OperationContract()]
          [WebInvoke(Method = "GET", 
                     BodyStyle = WebMessageBodyStyle.Bare, 
                     UriTemplate = "GetData/{value}")]
          string GetData(string value);
      }
    
  3. サービスクラスをこのコードに置き換えます

    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
    
  4. web.configはこのように見えます

    <system.web>
       <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <services>
          <service name="Service1">
              <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1">
              </endpoint>
          </service>
      </services>
      <behaviors>
          <endpointBehaviors>
              <behavior name="WebBehavior1">
                 <webHttp helpEnabled="True"/>
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    

  5. 実行して、GETメソッドを呼び出してみてください

誰かがこれまたは似たような機能を取得した場合、作業例に関する情報を返信できればとても親切です。

どうもありがとうございます

役に立ちましたか?

解決

私はあなたのサンプルを再現しました - 魅力のように機能します。

1つのポイント:サービス契約(public interface IService1)およびサービスの実装(public class Service1 : IService1).NETネームスペース内に存在しますか?

もしそうなら、あなたはあなたの *.svcとあなたの web.config 含める:

<services>
      <service name="Namespace.Service1">
          <endpoint address="" binding="webHttpBinding" 
                    contract="Namespace.IService1" 
                    behaviorConfiguration="WebBehavior1">
          </endpoint>
      </service>
  </services>

<service name="..."> 属性と <endpoint contract="..."> これを機能させるには、.NET名前空間を含める必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top