我试图在c#mvc web项目中创建一个wcf服务。我添加的类型为“WCF服务”的新项目,并添加所提供的接口测试方法:在web项目中托管WCF服务
[ServiceContract]
public interface ITest
{
[OperationContract]
void DoWork();
bool testWorking();
}
和所提供的服务:
public class Test : ITest
{
public void DoWork()
{
}
public bool testWorking()
{
return true;
}
}
然后,我已经走了过来web.config文件,并添加以下到system.ServiceModel标签:
<services>
<service name="Test" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="wsHttpBinding" contract="ITest">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
在这一点上,据我了解,我应该能够在浏览器中查看这一点,并得到一个测试消息告诉我这是关于我的时间补充了客户使用这项服务。但实际发生的事情是,我的浏览器下载.svc文件!
两个问题:
1)到底什么是我做错了什么?为什么我没有看到预期的消息?
2)有什么办法可以自动启动WCF测试工具来运行此服务?我能找到的唯一指导方针是从WCF项目开始。
更新:(SVC文件的内容 - 从评论抢下)
<%@ ServiceHost Language="C#" Debug="true"
Service="myemployersaddress.com.Test" CodeBehind="Test.svc.cs" %>
您是否在IIS中托管服务?看起来您没有为.svc安装正确的处理程序。另外请注意,服务的名称属性和端点的合同属性必须包含包含名称空间的类型名称 - 但它不是当前问题的根源。 – 2011-02-15 13:05:28
我确实对命名空间感到疑惑 - 因为它是在同一个项目中托管的,所以他们没有必要,但是谢谢澄清。我使用Visual Studio提供的默认服务器在IIS中运行此程序......并不完全知道如何安装正确的处理程序,如果它们不在那里的话。 – 2011-02-15 13:13:52
SVC文件中的`Service = ...`也应**引用服务**类的完全限定名 - 例如`服务= YourNamespace.Test`。这是你的svc文件中的情况?这里的服务条目不是任何类型的网址或类似的东西...... – 2011-02-15 13:42:41