简体   繁体   English

我们可以为WCF做URL重写吗

[英]can we do URL-REWRITE for WCF

We have built a WCF service for our customers and deployed the dlls. 我们已经为我们的客户构建了WCF服务并部署了dll。 Everything works perfectly, but we have been told we have to change the URL of the WCF. 一切正常,但是我们被告知必须更改WCF的URL。

Lets say, our current WCF URL is like below 可以说,我们当前的WCF URL如下所示

https://xxx.xxxxx.xxx/EGov/PostBox.svc

Now, they want us to change that URL to 现在,他们希望我们将该网址更改为

https://xxx.xxxxx.xxx/EGov/TransferService.svc

It is easy to change the file name from PostBox.svc to TransferService.svc but we have do it for our 100 customers and that is impossible. 将文件名从PostBox.svc更​​改为TransferService.svc很容易,但是我们已经为100个客户做到了,这是不可能的。 So, we are wondering if we can do URL-REWRITE from CONFIG files. 因此,我们想知道是否可以从CONFIG文件进行URL重写。

If we can do the URL-REWRITE from config files, then we will email the config files to each customer to put it into the right folder. 如果我们可以从配置文件中进行URL重写,那么我们将通过电子邮件将配置文件发送给每个客户,以将其放入正确的文件夹中。

I hope I made my question clear. 我希望我明确了我的问题。

URL rewriting in WCF WCF中的URL重写 在此处输入图片说明

Create a new WCF service application. 创建一个新的WCF服务应用程序。

Add Global.asax file. 添加Global.asax文件。

In Application_Start method add below lines: 在Application_Start方法中,添加以下几行:

 RouteTable.Routes.Add(new ServiceRoute("api/Service1", new WebServiceHostFactory(), typeof(Service1)));

Add WebInvoke in Operation Contract of Service Contract (interface IService1). 在服务合同的操作合同(接口IService1)中添加WebInvoke。

[OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetData?value={value}")]

Build and browse Project. 生成和浏览项目。

Check this : http://gunaatita.com/Blog/URL-rewriting-in-WCF/1052 检查此: http : //gunaatita.com/Blog/URL-rewriting-in-WCF/1052

No sure whether this will help you but i had some similar scenario where i have to rewrite the URL(for me i didn't have to show .svc file name to users. 不确定这是否对您有帮助,但是我遇到了一些类似的情况,我必须重写URL(对我来说,我不必向用户显示.svc文件名。

    public class Route : IHttpModule
   {
    public void Dispose()
    {
    }
    public void Init(HttpApplication context)
    {
        context.BeginRequest += delegate
        {
            //URL Rewriting 
            //---To remove the .svc extension service file name from URL----
             HttpContext cxt = HttpContext.Current;
            string path = cxt.Request.AppRelativeCurrentExecutionFilePath;
            {
                cxt.RewritePath(path.Insert(1, "/ReportingService.svc"), false);
            }

        };
    }
}

Hopefully this will help you at least in some way 希望这将至少在某种程度上帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM