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

Asked

Viewed 390 times

1

Hello,

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

The error that shows is an error by saying the following phrase: "The server encountered an error while processing the request. See the server logs for more details."

However, when I put in the WCF Test Client and click on Invoke, it returns to my list of objects. I don’t 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>
  • 1

    You consulted the logs that is said in the message?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.