Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a WCF application which is supposed to return JSON.
my service contract is like below
C#
[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>
XML
<system.serviceModel>
  <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="True"></serviceHostingEnvironment>-->
  <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">
        <!-- 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="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
Posted

1 solution

i found the answer so i am posting here. code was write but the setting i have in <system.servicemodel> tag in web.config was incorrect.
setting is as follows:--
XML
<system.serviceModel>
    <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="True"></serviceHostingEnvironment>-->
    <services>
      <service behaviorConfiguration="MobileTVWCFTest.Service1Behavior"        name="MobileTVWCFTest.MobileTVService">
        <endpoint address="" binding="webHttpBinding" 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">
          <!-- 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="false"/>

        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>

        <behavior name="MobileTVWCFTest.Service1EndBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900