2012-07-09 1 views
0

WcfTestClient.exe에서 실행중인 wcf를 사용하여 RestFull 서비스를 작성하려고합니다. 서비스를 추가하지 못했습니다. 서비스 메타 데이터에 액세스 할 수 없습니다. 서비스가 실행 중이고 메타 데이터가 노출되어 있는지 확인하십시오.

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

내가 config 파일에서 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; } 
    } 

서비스 1을 문제는 그 오류를 얻을 수 있다는 것입니다. 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"} 
      }; 
     } 
    } 
+0

브라우저 (IE/chrome/firefox/etc ..)에서 URL을 검색하여 서비스가 작동하는지 테스트 할 수 있습니다. 사용할 URL은 http : //localhost/ServiceApp/Service1.svc/XMLService/Employees와 같아야하며 XML 형식의 직원 정보 2 개를 반환해야합니다. – Rajesh

답변

2

With WCF 편안한 서비스 e, 실제로 서비스를 노출하거나 작업하기 위해 메타 데이터가 필요합니까? 내 대답은 아니오 야". 그것은 휴식의 원칙에 위배됩니다. 메타 데이터는 인터페이스 (작업)를 나타내며 REST 인터페이스는 고정되어 있습니다 (http 메소드). WcfTestClient는 SOAP 기반 서비스를 테스트하기위한 것입니다 (mex 바인딩을 통해 인터페이스를 노출해야하므로).

http get에 대한 RESTFUL 서비스 테스트는 매우 다양 할 수 있습니다. URL을 사용하여 브라우저에서 호출하면됩니다. 다른 HTTP 메소드를 테스트하려면 사용자 정의 클라이언트를 빌드해야합니다. 큰 작업 인 경우 Fiddler와 같은 도구를 사용하여 요청 데이터를 작성할 수 있습니다. 예를 볼 수 있습니다 here