The error is
On ctrl+F5 I am getting following error.
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Here Is my interface declaration
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace DealerAuditWCFService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IDealerAuditService" in both code and config file together.
[ServiceContract]
public interface IDealerAuditService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetDealerbyRegId/{regId}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Registration GetDealerbyRegId(string regId);
//[OperationContract]
//List<Registration> GetAllDealers();
//[OperationContract]
//void SaveDealerReg(List<Registration> regDetails);
}
}
Here is interface implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data.Entity;
namespace DealerAuditWCFService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "DealerAuditService" in code, svc and config file together.
public class DealerAuditService : IDealerAuditService
{
public Registration GetDealerbyRegId(string regId)
{
using (DealerAuditEntities dealerAudit = new DealerAuditEntities())
{
Registration regDetails = new Registration();
var reg = (from r in dealerAudit.tblRegistrationDetails
where r.regId == regId
select r).First();
regDetails.regId = reg.regId;
regDetails.Location = reg.Location;
regDetails.Region = reg.Region;
regDetails.typeOfAudit = reg.typeOfAudit;
return regDetails;
}
}
}
}
class for data members
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
namespace DealerAuditWCFService
{
[DataContract]
public class Registration
{
[DataMember]
public string regId { get; set; }
[DataMember]
public string channelPartnerName { get; set; }
[DataMember]
public string Location { get; set; }
[DataMember]
public string Region { get; set; }
[DataMember]
public string typeOfAudit { get; set; }
}
}
Here is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior" >
<serviceMetadata httpGetEnabled="True"/>
<!--<behavior name="servicebehavior">-->
<!-- 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>
</behaviors>
<services>
<service name="DealerAuditWCFService.DealerAuditService" behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="basicHttpBinding" contract="DealerAuditWCFService.IDealerAuditService" behaviorConfiguration="DealerAuditWCFService.DealerAuditService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="DealerAuditEntities" connectionString="metadata=res://*/DealerAuditEntityDataModel.csdl|res://*/DealerAuditEntityDataModel.ssdl|res://*/DealerAuditEntityDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.8.122;initial catalog=Beat_plan_db;persist security info=True;user id=sa;password=sa#122;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
As i am new to WCF,So trying to invoke a sample method through REST service.I keep on getting the same error.Please help me to solve this issue.