简体   繁体   English

WCF不添加服务

[英]WCF doesn't add service

I have a RESTful WCF service that I am trying to run there aren't any issues or errors except for, when it is running it says service added successfully but the service does not show at all. 我有一个要运行的RESTful WCF服务,除了它运行时,它说服务已成功添加,但该服务完全没有显示,没有任何问题或错误。 I know my question is a little bit vague sorry, but any ideas? 我知道我的问题有点含糊不清,但是有什么想法吗?

RestServiceImpl.svc.cs : 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 interface: 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 : 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM