0

WcfTestClient.exeで実行されているwcfを使用してRestFullサービスを構築しようとしています。問題は、エラーが発生することです。

Failed to add a service. Service metadata may not be accessible.

設定ファイルにmexエンドポイントを追加しましたが、解決しません:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyRest.Service"  behaviorConfiguration="ServBehave">
        <!--Endpoint for REST-->
        <endpoint
          address="XMLService"
           binding="webHttpBinding"
           behaviorConfiguration="restPoxBehavior"
           contract="MyRest.IService"/>
        <endpoint
            address="mex"
            binding="mexHttpBinding"
            contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServBehave" >
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <!--Behavior for the REST endpoint for Help enability-->
        <behavior name="restPoxBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

IService1.cs

 [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet(UriTemplate = "/Employees", ResponseFormat = WebMessageFormat.Xml)]
        Employee[] GetEmployees();

    }

    [DataContract]
    public class Employee
    {
        [DataMember]
        public int EmpNo { get; set; }
        [DataMember]
        public string EmpName { get; set; }
        [DataMember]
        public string DeptName { get; set; }
    }

Service1.cs

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class Service1 : IService1
    {
        public Employee[] GetEmployees()
        {
            return new Employee[] 
             {
                  new Employee() {EmpNo=101,EmpName="Mahesh",DeptName="CTD"},
                  new Employee() {EmpNo=102,EmpName="Akash",DeptName="HRD"}
             };
        }
    }
4

1 に答える 1

2

WCF Restfulサービスでは、サービスを公開したり、サービスを実行したりするために、実際にメタデータが必要ですか?答えはいいえだ"。それは休息の原則に反しています。メタデータはインターフェース(操作)を表し、RESTインターフェースは固定されています(httpメソッド)。WcfTestClientは、SOAPベースのサービスをテストするためのものです(mexバインディングを介してインターフェイスを公開する必要があるため)。

http getのRESTFULサービスのテストは、簡単に変えることができます。URLを使用して、ブラウザから呼び出す必要があります。他のhttpメソッドをテストするには、カスタムクライアントを構築する必要があります。これが大きな作業のように思われる場合は、Fiddlerなどのツールを使用してリクエストデータを作成することもできます。例はここで見ることができます

于 2012-07-09T10:01:49.000 に答える