因为我在网站上从.svc
中检索无法找到作为ServiceHost指令中的Service属性值提供的类型'TaskService'。
而不是在网络应用程序中
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TaskService
{
[OperationContract]
public List<int> GetTasks(int id, int type)
{
List<int> nodes = new List<int>();
return nodes;
}
}
配置文件:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TaskServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="TaskServiceBehavior" name="TaskService">
<endpoint address="" binding="basicHttpBinding" contract="TaskService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
答案 0 :(得分:0)
无论是Web还是WCF应用程序都无关紧要。重要的是你引用了 System.ServiceModel ,这是WCF的核心程序集。首先,您需要创建一个接口作为您的服务规范:
[ServiceContract(Namespace = "")]
public interface ITaskService
{
[OperationContract]
List<int> GetTasks(int id, int type);
}
然后,实施它:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TaskService : ITaskService
{
public List<int> GetTasks(int id, int type)
{
List<int> nodes = new List<int>();
return nodes;
}
}