WCF Restful Service :-Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata -
the error is
on ctrl+f5 getting following error.
failed add service. service metadata may not accessible. make sure service running , exposing metadata.
here 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: can use "rename" command on "refactor" menu change interface name "idealerauditservice" in both code , 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 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: can use "rename" command on "refactor" menu change class name "dealerauditservice" in code, svc , 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 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 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 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">--> <!-- avoid disclosing metadata information, set value below false , remove metadata endpoint above before deployment --> <servicemetadata httpgetenabled="true" /> <!-- receive exception details in faults debugging purposes, set value below true. set false before deployment 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 new wcf,so trying invoke sample method through rest service.i keep on getting same error.please me solve issue.
firstly, need decide if going expose rest or soap endpoint. decision complex , not topic in question here.
for rest, need use webhttpbinding, soap, either basichttpbinding or wshttpbinding.
however, produce metadata (at least of type supported proxy generator via visual studio add service reference functionality), you limited soap endpoint.
to consume rest endpoint need model same dtos service (or use same assembly defined), , use either httpclient or webclient (there advantages both).
Comments
Post a Comment