[英]For use WCF and create .svc is necessary a web application or in simple ASP.NET website run the .svc
Because in website i retrieve from .svc 因为在网站上我从.svc中检索
The type 'TaskService', provided as the Service attribute value in the ServiceHost directive could not be found. 找不到类型'TaskService',作为ServiceHost指令中的Service属性值提供。
And not in web application 而不是在Web应用程序中
[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;
}
}
And the config file: 和配置文件:
<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>
It doesn't matter if it is a Web or a WCF app. 它是Web还是WCF应用程序都没有关系。 The important thing is that you reference System.ServiceModel , that is the core assembly of WCF.
重要的是您引用System.ServiceModel ,它是WCF的核心程序集。 First of all, you need to create an interface to be your service specification:
首先,您需要创建一个接口作为您的服务规范:
[ServiceContract(Namespace = "")]
public interface ITaskService
{
[OperationContract]
List<int> GetTasks(int id, int type);
}
And then, implement it: 然后,实现它:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TaskService : ITaskService
{
public List<int> GetTasks(int id, int type)
{
List<int> nodes = new List<int>();
return nodes;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.