2013-07-25 1 views
-1

VS2012를 사용하여 새 WCF 웹 사이트 (Add-> New Web Site-> WCF Service)를 만들었습니다. 다음과 같이브라우저에서 RESTful 액세스를 지원하도록 WCF WebSite 구성

<?xml version="1.0"?> 
<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5"/> 
    <httpRuntime targetFramework="4.5"/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https"/> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 
</configuration> 

또한 나에게 초기 서비스 클래스를 제공합니다 : 다음 F5 시작하는

public class Service : IService 
{ 
    public string GetData(int value) 
    { 
     return string.Format("You entered: {0}", value); 
    } 

    public CompositeType GetDataUsingDataContract(CompositeType composite) 
    { 
     if (composite == null) 
     { 
      throw new ArgumentNullException("composite"); 
     } 
     if (composite.BoolValue) 
     { 
      composite.StringValue += "Suffix"; 
     } 
     return composite; 
    } 
} 

를이 나에게 다음 web.config 파일을 제공합니다 '박스 아웃'

프로젝트는 Service.svc를 포함하여 디렉토리 내용을 나열하는 브라우저 창을 시작합니다.

URL을 입력하여 GetData 메서드를 호출하고 싶습니다. 브라우저 주소 표시 줄에 무엇을 입력하고 브라우저에 URL을 입력하고 반환되는 JSON 형식 문자열을 볼 수 있도록 서비스를 구성 및/또는 장식하는 방법은 무엇입니까?

답변

1

마크 다음과 같은 속성과의 계약에서 운전 (IService 인터페이스) - [WebInvoke의 (방법 = BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "있는 GetData"GET "/ {id} ")] 그리고 GetData/[any number]를 추가하여 브라우저에서 서비스를 호출 해보십시오.

+0

문제가 발생하면 -http : //www.codeproject.com/Articles/167159/를 검색하십시오. 만드는 방법 - JSON-WCF-RESTful-Service-in-60-sec – vibhu