简体   繁体   English

REST与SOAP WCF服务 - 使用两者都有不利之处

[英]REST vs SOAP WCF Service - is there a downside for using both

When developing my WCF Service I originally planned using REST but later found out it will be called using SOAP. 在开发我的WCF服务时,我最初计划使用REST,但后来发现它将使用SOAP调用。 I have decorate my methods with both SOAP OperationalContract and REST WebInvoke but created only SOAP endpoint. 我用SOAP OperationalContract和REST WebInvoke装饰我的方法,但只创建了SOAP端点。

public interface IMyService
{

   [OperationContract]
   [WebInvoke(UriTemplate = "GetData/{ID}/{Name}", Method = "GET",
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.WrappedRequest)]
   string GetData(string ID, string Name);

}

My question is what are the possible implications of using both OperationalContract and WebInvoke , if any? 我的问题是,如果有的话,使用OperationalContractWebInvoke可能会带来什么影响? Are there downsides? 有缺点吗?

Should I keep it as it is, in case later I might need to add a REST endpoint? 我应该保持原样,以防万一我可能需要添加一个REST端点吗? Or should I remove WebInvoke ? 或者我应该删除WebInvoke

My question is what are the possible implications of using both OperationalContract and WebInvoke, if any? 我的问题是,如果有的话,使用OperationalContract和WebInvoke可能会带来什么影响? Are there downsides? 有缺点吗?

No, there are no downsides, other than you are adding code which may never be used. 不,除了添加可能永远不会使用的代码之外,没有任何缺点。

Also, for your info, OperationContract is for all WCF operations, not just for SOAP operations. 此外,对于您的信息,OperationContract适用于所有WCF操作,而不仅仅适用于SOAP操作。 You need it for REST also. 你也需要它用于REST。

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

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