开发者

What is the best practice for multiple WCF end point types? i.e.: JSON, JSONP, SOAP & POX?

What is the best practice for multiple WCF end point types? i.e.: JSON, JSONP, SOAP & POX? I am using WCF 3.5.

For instance, I have the following JSONP web service:

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
    }
}

Now, I need to expose a SOAP and POX version. My initial thought was to create a WCF Application Project for each service type endpoint. Then publish each one to an App directory under the main website.

  • RivWorks.Web.Service.SOAP -> http://rivworks.com/services/soap
  • RivWorks.Web.Service.POX -> http://rivworks.com/services/pox
  • RivWorks.Web.Service.JSON -> http://rivworks.com/services/json
  • RivWorks.Web.Service.JSONP -> http://rivworks.com/services/jsonp

I have an internal “Bus” that the working code lives in. I just want to wrap that bus code with service endpoints of various types. What is the best practice way to do this?

PS: Is there a tool for merging the WCF web.config(s) into the main site’s web.config?

TIA

-kb


UPDATE: How do you go about handling the different decorators that can be applied to a Method signature. i.e. - compare the following Methods (which are identical) and the decorators associated with them:

Decorator for a POX endpoint:

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

vs Decorator for a JSON endpoint:

[OperationContract]
[WebGet(ResponseFormat = WebM开发者_如何学运维essageFormat.Json)]
public bool ValidateUser(string UserName, string Password)
{
    ...
}

And here is another example where the method signature itself changes:

[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 a POX endpoint type:

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


Why would you want a separate project? WCF can expose many services on many endpoints, just in a single project.

Simply add the additional endpoints as .svc files. Do whatever you need to do with routing if you're sensitive to the ".svc" at the end (though remember that humans don't see the .svc).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜