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="data source=CHRISPHAN-HP\SQLEXPRESS;initial catalog=estocktake;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>
当我测试它使用WCF测试工具,所述功能正在工作。
任何建议将是一个很大的帮助,对不起,这个长的帖子后。
-UPDATE- 仍然无法在YouTube视频中有可能在浏览器中运行服务。 使用 VS2013的Web SQL IIS快递
你有db数据? – Sajeetharan
@Sajeetharan是的,我的数据库有记录,它在测试客户端工作。 – Chris
@Chris看你的浏览器控制台有什么? – Mairaj