创建WCF服务没有SVC文件的方法

首先 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,
web.config for SVC less 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文件了
 
 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值