带SQL表的WCF - 公开元数据
问题描述:
我开发了一个小型WCF服务,它从表中获取所有记录。它看起来像:带SQL表的WCF - 公开元数据
IService1.cs
:
[ServiceContract]
public interface IService1
{
List<badanieCis> GetRecords();
}
Service1.svc.cs
:
public List<badanieCis> GetRecords()
{
przychodniaEntities dataContext = new przychodniaEntities();
return dataContext.badanieCis.ToList();
}
而且我得到一个消息:无法添加服务。服务元数据可能无法访问。确保您的服务正在运行,揭露元
什么我做了一些后,研究是改变SVC文件标记为这一个:
<%@ ServiceHost Language="C#" Debug="true"
Service="Harvesting.Service.HarvestingService" CodeBehind="Service1.svc.cs" %>
但仍然一无所获。
我web.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="przychodniaEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DAREK-PC\SQLExpress;initial catalog=przychodnia;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
答
你缺少在配置文件中的服务定义。你需要像这样:
<services>
<service behaviorConfiguration="..." name="Service1 with namespace">
<endpoint address="..." name="..." binding="wsHttpBinding" bindingConfiguration="...." contract="IService1 with unterface" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<services>
...
你可以用这个tool来帮助配置。
你在哪里托管它? IIS?你的配置在哪里? – Aliostad 2012-04-04 08:27:59
只是在开发服务器上测试,我已经添加配置 – dargod 2012-04-04 08:32:32