EliasMP EliasMP - 9 days ago 6
C# Question

Show json´s result in browser

I created a WCF services and I suppose is working because when I launch

Services1.svc.cs
testing´s client is opened. Then I invoke my method and I get the proper Data in a JSON (testing´s client window).

But when I launch all proyect, I dont know how to access to the JSON´s url, for checking the JSON´s data by Mozilla... I need this url for knowing how to set Retrofit´s values (android) for consuming WCF.

--Service1.svc.cs--

[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();


Thanks Mates...

EDITED:

I will consume this WCF in Android, but it never mind.
First at All, I need to get the url for seeing the JSON through browser.
Then, I have to set Retrofit with baseURL and get Method, but I will (i hope) get them by the previous url.

Answer

Well,

Finally I got the solution. Stupid one... I don´t have to serialize the data result when I have anottations as well. Just work returning the list of object...

    [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>

Then I can watch the JSON result by browser, using http://localhost:8080/Service1.svc/pisosA

Thanks Mates.