在IIS中部署WCF服务

在IIS中部署WCF服务

本文介绍了在IIS中部署WCF服务时消除.svc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了WCF服务,我需要在IIS中部署。执行此操作的标准方法是创建svc文件,其中包含要创建的详细信息服务主机。



如果我需要访问服务操作,我必须使用http:// localhost:PortNumber / VirtualDirectory / svcfile.svc / MyService



我想避免在URL中使用svc文件路径。



有两个问题



1.如何在不使用svc文件的情况下在IIS中部署WCF服务?

2.如何使用http:// localhost等简单URL访问我的服务/ MyService

I have WCF service created which i need to deploy in IIS. Standard way of doing this is creating svc file which contains the details service host to be created.

With this approach if i need to access the service operation i have to use http://localhost:PortNumber/VirtualDirectory/svcfile.svc/MyService

I want to avoid using svc file path in URL.

There are two questions

1. How do i deploy my WCF service in IIS without using svc file ?
2. How do i access my service with simple URL like http://localhost/MyService

推荐答案


<servicehostingenvironment aspnetcompatibilityenabled="true">
      <serviceactivations>
        <add factory="System.ServiceModel.Activation.ServiceHostFactory" relativeaddress="Service.svc" service="Your Service" />
      </serviceactivations>

    </servicehostingenvironment>







现在您可以使用没有物理svc文件的路径访问服务http:/ /lcaolhost/VirtualDirectory/Service.svc / yourService



要避免URL中的svc路径,请在服务启动期间使用Global.asax文件使用路由



var routes = RouteTable.Routes;

routes.Add(new ServiceRoute(RoutePrefix,

new WebServiceHostFactory(),服务类型));




Now you can access the service using the path without the physical svc file http://lcaolhost/VirtualDirectory/Service.svc/YourService

To avoid the svc path in URL use routing during service start using Global.asax file

var routes = RouteTable.Routes;
routes.Add(new ServiceRoute("RoutePrefix",
new WebServiceHostFactory(), type of Service));


这篇关于在IIS中部署WCF服务时消除.svc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:39