2011-01-12 49 views
1

多個WCF終點類型的最佳做法是什麼?即:JSON,JSONP,SOAP & POX?我使用WCF 3.5。多個WCF終點類型的最佳做法是什麼?即:JSON,JSONP,SOAP&POX?

舉例來說,我有以下的JSONP Web服務:

namespace RivWorks.Web.Service.JSONP 
{ 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceContract(Name = "Negotiate", Namespace = "http://rivworks.com/Services/2009/01/15")] 
    public class Negotiate //: svcContracts.INegotiateService 
    { 
     #region Constructors 
     public NegotiateService() { } 
     #endregion 

     #region Methods 
     [OperationContract] 
     [WebGet(ResponseFormat = WebMessageFormat.Json)] 
     [JSONPBehavior(callback = "method")] 
     public dto.NegotiateSetup GetSetup(string method, string jsonInput) 
     { … } 

     [OperationContract] 
     [WebGet(ResponseFormat = WebMessageFormat.Json)] 
     [JSONPBehavior(callback = "method")] 
     public List<dto.NegotiateSetup> GetSetupAll(string method, string jsonInput) 
     { … } 
     #endregion 
    } 
} 

現在,我需要暴露SOAP和POX版本。我最初的想法是爲每個服務類型端點創建一個WCF應用程序項目。然後將其發佈到主網站下的App目錄中。

我有一個內部的「公交車」,工作代碼存在於我只是想換擁有各類服務端點總線代碼。什麼這樣做的最佳做法嗎?

PS:是否有一個工具將WCF web.config(s)合併到主站點的web.config中?

TIA

-kb


UPDATE: 你怎麼去處理,可應用於方法簽名不同的裝飾。即 - 比較與它們相關聯的以下的方法(其是相同的)和裝飾:

裝飾爲一個POX端點:

[OperationContract] 
[WebGet(ResponseFormat = WebMessageFormat.Xml)] 
public bool ValidateUser(string UserName, string Password) 
{ 
    ... 
} 

VS 裝飾爲一個JSON端點:

[OperationContract] 
[WebGet(ResponseFormat = WebMessageFormat.Json)] 
public bool ValidateUser(string UserName, string Password) 
{ 
    ... 
} 

這裏是另一個方法簽名本身發生變化的例子:

[OperationContract] 
[WebGet(ResponseFormat = WebMessageFormat.Json)] 
[JSONPBehavior(callback = "method")] 
public dto.NegotiateSetup GetSetup(string method, string jsonInput) 
{ 
    // Deserialize the input and get all the data we need... 
    JObject o = Newtonsoft.Json.Linq.JObject.Parse(jsonInput); 
    string urlRef = String.Format("{0}", o["ref"]).Drop("\""); 
    string clientDate = String.Format("{0}", o["dt"]).Drop("\""); 
    string stringProductID = String.Format("({0})", o["productId"]).Drop("\"").Drop("(").Drop(")"); 
    string SKU = String.Format("{0}", o["sku"]).Drop("\""); 
    string env = String.Format("{0}", o["env"]).Drop("\""); 
    string stringCompanyID = String.Format("({0})", o["CompanyId"]).Drop("\"").Drop("(").Drop(")"); 
    string boolPortalFlag = String.Format("({0})", o["PortalFlag"]).Drop("\"").Drop("(").Drop(")"); 
... 
} 

vs POX端點類型:

[OperationContract] 
[WebGet(ResponseFormat = WebMessageFormat.Xml)] 
public dto.NegotiateSetup GetSetup(string urlRef, string clientDate, string stringProductID, string SKU, string env, string stringCompanyID, string boolPortalFlag) 
{ 
... 
} 

回答

1

爲什麼你想要一個單獨的項目? WCF可以在許多端點上公開許多服務,僅在一個項目中。

只需將其他端點添加爲.svc文件即可。如果你對最後的「.svc」敏感,可以做任何你需要做的工作(儘管記住人類看不到.svc)。

+0

任何示例?設置配置文件仍然困擾着我。如果我能在一個項目中(理智地)做到這一點,我更願意這樣做。另外,既然你說過設置了一個不同的.svc文件,我假設你的意思是使用WCF服務庫而不是WCF服務應用程序? – 2011-01-13 22:30:38

相關問題