我想让我的svc文件在IIS下工作。在我的项目中,当我按F5时,我得到了svc的工作。所以我知道一切都好,对不对?除IIS外。WCF如何启用元数据?
我正在使用Windows XP Pro计算机,并在IIS中添加了一个虚拟目录。
这里是我的代码: IcarePlanActions(项目:A)
namespace WcfServiceLibrary
{
[ServiceContract]
public interface ICarePlanActions
{
[OperationContract]
List<string> GetAllClients();
}
}
客户:(项目:A)
namespace WcfServiceLibrary
{
public class Client : ICarePlanActions
{
public List<string> GetAllClients()
{
List<string> clients = new List<string>();
clients.Add("Hendrik de Jong");
clients.Add("Miep de Berg");
clients.Add("Jaap Jongeneel");
clients.Add("Joop Prakman");
clients.Add("Pieter Schaakman");
return clients;
}
}
}
Web.config文件(项目:B)
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="CarePlanService.Service1Behavior"
name="WcfServiceLibrary.Client">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.ICarePlanActions">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CarePlanService.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
CarePlan.svc
<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Client" %>
当我运行此服务(这是对IIS)与wfctestclient我得到这个错误
Error: Cannot obtain Metadata from http://localhost/CarePlanService/CarePlan.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.
我在做什么错?
SOLUTION
我没有得到服务IIS下工作。首先,我手动创建一个虚拟目录,并指向svc所在的directiry。这没有奏效。我不知道为什么。
然后我去了Visual Studio和更改服务器设置(鼠标右键的项目,属性,标签网页,单击Use local IIS Web Server
并单击Create Virtual Directory
。当我这样做,它的工作IIS下上面的代码。
编辑标题 - 这与C#编程语言无关。 – 2010-01-18 21:35:39
我没有这样使用过WCF,但是你应该把你的服务实现放在datacontract里面吗?如果是这样,那么合同中就没有定义数据库。只是看起来很奇怪。但我从来没有在IIS托管... – magnus 2010-01-18 22:22:04
@Martijn:真正愚蠢的问题:当你试图使用WcfTestClient连接,是网站吗?如果你做了这里提出的修改(删除[DataContract],为mex端点使用“mexHttpBinding”),我完全没有困难获取元数据。但是,你必须做一个“浏览器查看”上的* .svc文件首先,为了启动内置的Web服务器 - 然后你可以用你的WcfTestClient – 2010-01-19 07:08:24