WCF-und JSON-binding

Ich versuche zum erstellen einer wcf-service, der json zurückgibt. Ich habe einige Probleme mit meiner config-Datei und ich weiß auch nicht, wie es zu testen.

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

Bekomme ich noch

"Nicht hinzufügen können, das Verhalten der Erweiterung webhttp zu dem service-Verhalten
Namen JSONEndpointBehavior weil das zugrunde liegende Verhalten geben tut
implementiert nicht die IServiceBehaviorInterface"

Kontakt ist folgendermaßen definiert :

[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 ist folgendermaßen definiert :

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

Die Umsetzung der GetContact:

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

Mein service läuft auf einem anderen computer in meinem lan. Basis-Adresse wie ist: http://192.168.1.xxx/ContactLibraryService. ContactLibraryService ist die von IIS gehostet wird und umgewandelt wird in eine Anwendung.

InformationsquelleAutor sebastian.roibu | 2012-03-23

Schreibe einen Kommentar