我有一个RESTful WCF服务,我试图在那里运行没有任何问题或错误,除了,当它运行时说服务添加成功但服务根本没有显示。我知道我的问题有点含糊不清,但有什么想法吗?
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 FROM tblCompany", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
}
}
}
IRestService.cs
界面:
[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 fully qualified, address is relative to 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>