Return Json from an Object List - WCF C # .NET VS 2010

1

Hello,

I want to return a list of objects in json by wcf. When I put in to return the string, it returns quietly. But when I return the list, the error.

The error that displays is an error saying the following sentence: "The server encountered an error while processing the request. Please see the server logs for more details."

However, when I put it in the WCF Test Client and click on Invoke , it returns to my list of objects. I do not know what to do.

I would like help. Thank you.

Class

[DataContract]
public class Dvd
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string Nome { get; set; }

    [DataMember]
    public int AnoLancamento { get; set; }

    [DataMember]
    public Categoria Categoria { get; set; }
}

WCF - Class (file.svc)

public class DvdService : IDvdService
{
    public List<Dvd> ServicoBuscarTodosDvds(){
        DvdBusiness business = new DvdBusiness();
        return business.GetAll();
    }
}

WCF - Interface (Ifile.cs)

[ServiceContract]
public interface IDvdService
{
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    List<Dvd> ServicoBuscarTodosDvds();
}

Web.Config

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
     <bindings>
       <webHttpBinding>
     <binding name="padrao"/>
         </webHttpBinding>
     </bindings>
     <protocolMapping>
       <add scheme="http" binding="webHttpBinding"/>
     </protocolMapping>
<services>
  <service name="DvdLibrary.Service.DvdService" behaviorConfiguration="httpTeste">
    <endpoint
      address="http://localhost:5423/DvdService.svc"
      binding="webHttpBinding"
      behaviorConfiguration="web"
      bindingConfiguration="padrao"
      contract="DvdLibrary.Service.IDvdService"
      ></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="httpTeste">
      <!-- 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 name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
 </system.serviceModel>
  <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
  </customHeaders>
</httpProtocol>
  </system.webServer>
 </configuration>
    
asked by anonymous 24.08.2015 / 21:43

0 answers