i have a WCF application which is supposed to return JSON.
my service contract is like below
[ServiceContract(Name = "MobileTV", Namespace = "MobileTVWCF")]
public interface IMobileTVService
{
[OperationContract]
string GetData(int value);
[OperationContract]
[WebGet(UriTemplate = "GetDataUsingDataContract/{deviceID}", ResponseFormat = WebMessageFormat.Json)]
Customer GetDataUsingDataContract(int deviceID);
}
[DataContract]
public class Customer
{
[DataMember]
public int CustomerID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public bool IsActive { get; set; }
[DataMember]
public string MobileNo { get; set; }
[DataMember]
public bool IsAuthenticated { get; set; }
}
and my service Implemetation is as bellow
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MobileTVService : IMobileTVService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public Customer GetDataUsingDataContract(int deviceID)
{
Customer cust = new Customer();
SqlParameter[] paramsToStore = new SqlParameter[1];
paramsToStore[0] = new SqlParameter("@deviceID", SqlDbType.Int);
paramsToStore[0].Value = deviceID;
SqlDataReader sqlDataReaderObj = SqlHelper.ExecuteReader(@"Data Source=192.168.205.71\Development;Initial Catalog=PCTV;User ID=sa;Password=s@123", CommandType.StoredProcedure, StoredProcedures.GetCustomerDetails, paramsToStore);
if (sqlDataReaderObj.HasRows)
{
var customSqlDatareder = new CustomSqlDataReader(sqlDataReaderObj);
while (customSqlDatareder.Read())
{
cust.CustomerID = Convert.ToInt32(customSqlDatareder.GetString("intCustomerId"));
cust.MobileNo = customSqlDatareder.GetString("vcMobileNumber");
cust.Name = customSqlDatareder.GetString("Name");
cust.IsActive = customSqlDatareder.GetBoolean("boolISActive");
}
}
else
{
cust = null;
}
return cust;
}
}
i have done some setting in web.config in <system.servicemodel>
<system.serviceModel>
<services>
<service behaviorConfiguration="MobileTVWCFTest.Service1Behavior"
name="MobileTVWCFTest.MobileTVService">
<endpoint address="" binding="wsHttpBinding" contract="MobileTVWCFTest.IMobileTVService" behaviorConfiguration="MobileTVWCFTest.Service1EndBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MobileTVWCFTest.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MobileTVWCFTest.Service1EndBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
can any one tell me that where i m doing wrong coz when i am running my code it throwing exception
The endpoint at 'http://localhost:1515/MobileTVService.svc' does not have a Binding with the None MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings