2017-02-16 80 views
1

問候語,目前我正在瀏覽器中以xml格式顯示服務。爲什麼Web服務中的功能無法正常工作?

但是,它顯示一個空白頁面,是否有解釋爲什麼?防火牆問題? 這裏是所有的文件。

IProductService1.cs

using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Text; 


namespace WCFRESTfulService 
{ 
// NOTE: You can use the "Rename" command on the "Refactor" menu to change  the interface name "IService1" in both code and config file together. 
[ServiceContract] 
public interface IProductService1 
{ 
    [OperationContract] 
    [WebGet] 
    List<product> GetAllProducts(); 

    [OperationContract] 
    [WebGet] 
    product GetProducts(string id); 

} 

} 

ProductService1.svc.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace WCFRESTfulService 
{ 
// NOTE: You can use the "Rename" command on the "Refactor" menu to change  the class name "Service1" in code, svc and config file together. 
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging. 
public class Service1 : IProductService1 
{ 

    public List<product> GetAllProducts() 
    { 
     using(var db=new estocktakeEntities()) 
     { 
      return db.products.ToList(); 
     } 
    } 


    public product GetProducts(string id) 
    { 
     Int32 _id = Convert.ToInt32(id); 
     using(var db=new estocktakeEntities()) 
     { 
      return db.products.SingleOrDefault(p => p.invtid == id); 


     } 


    } 
} 
} 

的Web.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit  http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework"  type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,  EntityFramework, Version=6.0.0.0, Culture=neutral,  PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 

    <system.serviceModel> 
    <services> 
     <service name="myService.ProductService"> 
     <endpoint address="" behaviorConfiguration=""  binding="webHttpBinding" contract="MyService.IProductService"></endpoint>   
     </service> 
    </services> 
    <behaviors> 
    <endpointBehaviors> 
    <behavior name="restbehaviour"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<protocolMapping> 
    <add scheme="https" binding="basicHttpBinding"/> 
</protocolMapping> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment> 
    </system.serviceModel> 



    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true" /> 
    </system.webServer> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <connectionStrings> 
    <add name="Model1" connectionString="data source=CHRISPHAN-HP\SQLEXPRESS;initial catalog=estocktake;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /><add name="estocktakeEntities" connectionString="metadata=res://*/productmodel.csdl|res://*/productmodel.ssdl|res://*/productmodel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CHRISPHAN-HP\SQLEXPRESS;initial catalog=estocktake;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings> 
</configuration> 

當我測試它使用WCF測試工具,所述功能正在工作。

測試網站上 The service page which is working

添加功能到URL Get all product is not displaying

任何建議將是一個很大的幫助,對不起,這個長的帖子後。

-UPDATE- 仍然無法在YouTube視頻中有可能在瀏覽器中運行服務。 使用 VS2013的Web SQL IIS快遞

+0

你有db數據? – Sajeetharan

+0

@Sajeetharan是的,我的數據庫有記錄,它在測試客戶端工作。 – Chris

+0

@Chris看你的瀏覽器控制檯有什麼? – Mairaj

回答