我想創建一個返回json的wcf服務。我的配置文件有一些問題,我也不知道如何測試它。WCF和JSON綁定
<?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>
我仍然得到
「無法將行爲擴展webhttp添加到服務行爲 名
JSONEndpointBehavior
因爲基礎行爲類型不 未實現IServiceBehaviorInterface
」
聯繫是定義爲:
[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的定義如下:
[ServiceContract]
public interface IContactServiceJSON
{
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "")]
Contact GetContact();
}
的GetContact
實施:
public Contact GetContact()
{
return new Contact()
{
firstName = "primulNume",
lastName = "alDoileaNume",
age = 33,
city = "Cluj",
country = "Romania",
email = "[email protected]",
street = "Bizusa 8"
};
}
我的服務我的局域網的另一臺計算機上運行。基地址如下:http://192.168.1.xxx/ContactLibraryService。 ContactLibraryService
由IIS託管並轉換爲應用程序。
我修改了名稱並更新了我的帖子。 – 2012-03-23 16:00:12
'JSONEndpointBehavior'應該不是Service但是Endpoint行爲 – paramosh 2012-03-23 16:38:13