2014-10-10 39 views
1

是否可以保留以下地址並使用ServiceStack重新實現它?如何使用ServiceStack重新實現legacy aspx並維護地址?

http://example.com/Routing/LeadPost.aspx?LeadType=AAA&MYId=3000 

我沒有訪問原始代碼,因爲它是誰創造了它一個第三方,但我不知道是什麼職位呢,一個巨大的XML包。這個我完全模仿了一個簡單的請求DTO和服務,但是我並不清楚尋址部分,或者它甚至是合理的。以下是我迄今爲止的實施情況。當你安裝ServiceStack

public class Service : ServiceStack.Service 
{ 
    public IMessageQueueClient MessageQueueClient { get; set; } 

    public object Post(LeadInformation request) 
    { 
     if (request == null) throw new ArgumentNullException("request"); 

     var sw = Stopwatch.StartNew(); 

     MessageQueueClient.Publish(request); 

     return new LeadInformationResponse 
     { 
      TimeTakenMs = sw.ElapsedMilliseconds, 
     }; 
    } 
} 

謝謝 斯蒂芬

回答

1

您可以使用此路由定義來處理傳統ASP.NET WebForms的請求:

[Route("/Routing/LeadPost.aspx")] 
public class LegacyLeadPost 
{ 
    public string LeadType { get; set; } 
    public int MyId { get; set; } 
} 

這將讓你處理與LeadTypeMyId性能所需的路線填充:

/Routing/LeadPost.aspx?LeadType=AAA&MYId=3000 

的替代方法是使用WebForms頁面並調用ServiceStack,ServiceStack Integration文檔探索從外部ASP.NET MVC或WebForms Web框架訪問ServiceStack的不同方式。

+0

絕對太棒了,只是單元測試它。 – 2014-10-10 20:00:50

0

(至少到3版本,這是我最後一次使用),它增加了一些對你的應用程序的Web.Config file看起來像:

<system.web> 
    <httpHandlers> 
    <add path="somePath/*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" /> 
    </httpHandlers> 
</system.web> 

如果修改path屬性以匹配您的傳統URL,它可能會起作用。然後再次,不知道其他HttpHandler是爲您的應用程序設置的,這是不可能的。另外請記住,您可能會引入衝突,因爲有一個HttpHandler可將所有.aspx網址傳遞給.NET Webforms Page基類以及應用程序中的所有其他代碼隱藏文件。