首先 SVC文件是用于在IIS上承载WCF服务的,现在做的是不需要SVC文件怎么使用WCF服务,首先启动VS2012创建一个空的项目,然后添加类库例如项目名WelcomeService,然后添加引用System.ServiceModel,之后添加一个接口文件IWelcomeService.cs到你的项目里,添加System.ServiceModel命名空间和服务契约ServiceContract,在服务契约下添加一个方法GreetWithMessage,返回类型为一个字符串,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WelcomeService
{
public class WelcomeService : IWelcomeService
{
public string GreetWithMessage(string name)
{
return name + " Welcome to mithunvp.com !!";
}
}
}
然后创建ASP.NET空Web站点的托管应用程序为WCF,
ASP.NET是通过ServiceActivations是主要的设置,使访问WCF服务修改WEBCONFIG文件
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment >
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./WelcomeServiceHost/WelcomeService.svc"
service="WelcomeService.WelcomeService" />
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这样通过上述配置就可以实现承载WCF服务的目的,不需要SVC文件了