c# - WCF doesn't add service -
i have restful wcf service trying run there aren't issues or errors except for, when running says service added service not show @ all. know question little bit vague sorry, ideas?
restserviceimpl.svc.cs
:
public class restserviceimpl : irestserviceimpl { public string xmldata(string id) { return ("you requested product" + id); } public string jsondata(string id) { return ("you requested product" + id); } public company getcompany(string compid) { company comp = new company(); { sqlconnection con = new sqlconnection(); con.connectionstring = ""; con.open(); sqlcommand cmd = new sqlcommand("select companyname tblcompany", con); con.open(); sqldatareader reader = cmd.executereader(); } } }
irestservice.cs
interface:
[servicecontract] public interface irestserviceimpl { [operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.xml, bodystyle = webmessagebodystyle.wrapped, uritemplate = "xml/{id}")] string xmldata(string id); [operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "json/{id}")] string jsondata(string id); [operationcontract] [webget(uritemplate = "/getcompany/{compid}", requestformat = webmessageformat.json, responseformat = webmessageformat.json)] company getcompany(string compid); } [datacontract] public class company { [datamember] public string compid { get; set; } [datamember] public string company { get; set; } } }
web.config
:
<?xml version="1.0"?> <configuration> <connectionstrings> <add name="truckdbwcf" connectionstring="" providername="system.data.sqlclient" /> </connectionstrings> <appsettings> <add key="aspnet:usetaskfriendlysynchronizationcontext" value="true" /> </appsettings> <system.web> <compilation debug="true" targetframework="4.5" /> <httpruntime targetframework="4.5"/> </system.web> <system.servicemodel> <services> <service name="restservice.restserviceimpl" behaviorconfiguration="servicebehaviour"> <!--service endpoint--> <!--unless qualified, address relative base address supplied above--> <endpoint address="" binding="webhttpbinding" contract="restservice.irestserviceimpl" behaviorconfiguration="web"/> <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange"/> </service> </services> <behaviors> <endpointbehaviors> <behavior name="web"> <webhttp /> </behavior> </endpointbehaviors> <servicebehaviors> <behavior name="servicebehaviour"> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="false" /> </behavior> <behavior name=""> <servicemetadata httpgetenabled="true" httpsgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="false" /> </behavior> </servicebehaviors> </behaviors> <protocolmapping> <add binding="basichttpsbinding" scheme="https" /> </protocolmapping> <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" /> </system.servicemodel> <system.webserver> <httpprotocol> <customheaders> <add name="access-control-allow-origin" value="*"/> <add name="access-control-allow-headers" value="content-type, accept" /> <add name="access-control-allow-methods" value="post,get,options" /> <add name="access-control-max-age" value="1728000" /> </customheaders> </httpprotocol> <modules runallmanagedmodulesforallrequests="true"/> <directorybrowse enabled="true"/> </system.webserver> </configuration>
this blog cover similar case.
Comments
Post a Comment