I am trying to create a wcf service that returns json. I have some problems with my configuration file and I also don't know how to test it.
<?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> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
I'm still getting
"It is not possible to add a webhttp behavior extension to the JSONEndpointBehavior names service behavior because the main type of behavior is not to implement IServiceBehaviorInterface "
Contact is defined as follows:
[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 is defined as:
[ServiceContract] public interface IContactServiceJSON { [OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")] Contact GetContact(); }
GetContact implementation:
public Contact GetContact() { return new Contact() { firstName = "primulNume", lastName = "alDoileaNume", age = 33, city = "Cluj", country = "Romania", email = " ceva@mail.com ", street = "Bizusa 8" }; }
My service runs on another computer in my computer. Base address: http://192.168.1.xxx/ContactLibraryService . ContactLibraryService is hosted in IIS and converted to an application.
source share