WCF et JSON de liaison

Je suis en train de créer un service wcf qui renvoie du json. J'ai quelques problèmes avec mon fichier de config et j'ai aussi ne sais pas comment le tester.

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="ContactLibraryJSON.ContactLibrary">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="JSONEndpointBehavior"
          contract="ContactLibraryJSON.IContactServiceJSON" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.1.31/ContactLibraryJSON" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="JSONEndpointBehavior">
          <webHttp/>
        </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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Je reçois toujours

"Impossible d'ajouter le comportement de l'extension webhttp le comportement de service
les noms de JSONEndpointBehavior parce que le comportement sous-jacent de type t
ne pas mettre en œuvre la IServiceBehaviorInterface"

Contact est défini comme :

[DataContract(Name="Contact")]
public class Contact
{        
    [DataMember(Name="FirstName")]
    public string firstName=null;
    [DataMember(Name="LastName")]
    public string lastName=null;
    [DataMember(Name="Email")]
    public string email=null;
    [DataMember(Name = "Age")]
    public int age = 0;
    [DataMember(Name = "Street")]
    public string street=null;
    [DataMember(Name = "City")]
    public string city=null;
    [DataMember(Name = "Country")]
    public string country=null;
}

IContactService est défini comme :

[ServiceContract]
public interface IContactServiceJSON
{
    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")]
    Contact GetContact();        
}

La mise en œuvre de GetContact:

public Contact GetContact()
{
    return new Contact()
    {
        firstName = "primulNume",
        lastName = "alDoileaNume",
        age = 33,
        city = "Cluj",
        country = "Romania",
        email = "[email protected]",
        street = "Bizusa 8"
    };
}

Mon service s'exécute sur un autre ordinateur de mon réseau local. Adresse de Base est comme: http://192.168.1.xxx/ContactLibraryService. ContactLibraryService est hébergé par IIS et est converti à une application.

OriginalL'auteur sebastian.roibu | 2012-03-23