2016-06-06 5 views
0

나는 WCF 서비스를 만들었고 Services1.svc.cs 테스트 클라이언트를 열었 기 때문에 작동하고 있다고 가정합니다. 그런 다음 메서드를 호출하고 적절한 데이터를 JSON (테스트 클라이언트 창)에서 가져옵니다.브라우저에서 json의 결과 표시

하지만 모든 proyect를 시작하면 Mozilla에서 JSON의 데이터를 확인하는 JSON의 URL에 액세스하는 방법을 알지 못합니다 ...이 Retrofit 값을 설정하는 방법을 알기 위해이 URL이 필요합니다 (안드로이드)를 소비합니다. 편집을 할

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA/")] 
public String devolverPisosA() 
    { 
     List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler 
          select piso).ToList(); 

     string json = JsonConvert.SerializeObject(consultaPA); 

     return json; 

    } 

--Iservice--

[OperationContract] 
String devolverPisosA(); 

감사 메이트

--Service1.svc.cs--

...

:

나는 소비한다 안드로이드 에서이 WCF,하지만 절대 신경 안써. 처음에는 브라우저를 통해 JSON을 볼 수있는 URL을 가져와야합니다. 그런 다음 baseURL을 사용하여 Retrofit을 설정하고 Method를 가져와야하지만 이전 url을 통해 얻을 수 있습니다.

+0

테스트 클라이언트의 주소는 무엇입니까 ...? –

+0

http : // localhost : 52896/Service1.svc –

+0

테스트 클라이언트는 Visual Studio에서 열어 WCF 용도를 테스트 할 수있는 창입니다. WCF 클래스를 실행하면 열립니다. –

답변

0

음,

마지막으로 해결책을 얻었습니다. 어리석은 사람 ... 나는 anottations가있을 때 데이터 결과를 직렬화해야하지 않는다. 그냥 ... 객체의리스트를 돌려 작동

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA")] 
public String devolverPisosA() 
    { 
     List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler 
          select piso).ToList(); 

     return consultaPA; 

    } 

<system.serviceModel> 
    <services> 
     <service name="ProyectoJosephWCF.Service1" behaviorConfiguration="ServiceBehavior"> 
     <endpoint binding="webHttpBinding" 
        contract="ProyectoJosephWCF.IService1" 
        behaviorConfiguration="webHttp"/> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 

     <behavior name="ServiceBehavior" > 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 


     <behavior> 
      <!-- 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> 

은 그 때 나는 http://localhost:8080/Service1.svc/pisosA

감사 메이트를 사용하여 브라우저를 사용하여 JSON 결과를 볼 수 있습니다.