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

时间:2016-10-30 04:32:25

标签: c# rest wcf soap

在开发我的WCF服务时,我最初计划使用REST,但后来发现它将使用SOAP调用。我用SOAP WebInvoke和REST 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); } 装饰我的方法,但只创建了SOAP端点。

OperationalContract

我的问题是,使用WebInvokeWebInvoke的可能含义是什么?有缺点吗?

我应该保持原样,以防以后我可能需要添加REST端点吗?或者我应该删除class MainClass(): def __init__(self): while True: rawData=self.receiveData(file) #a made up function to receive data stuffOne, stuffTwo, stuffThree, stuffFour, data=self.MainParseFunction(rawData) #returns four things and some data if stuffOne=="a": self.functionOne(data) print("Output of Function One") elif stuffTwo=="b": self.functionTwo(data) print("Output of Function Two") elif stuffThree=="c": self.functionThree(data) print("Output of Function Three") elif stuffFour=="d": self.functionFour(data) print("Output of Function Four") def MainParseFunction(self, data): '''Do some stuff to the data being passed to my function and return a bunch of variables to be use in the other functions ''' def functionOne(self, data): '''Do some stuff to the data being passed to my function and return a bunch of variables to be printed ''' def functionTwo(self, data): '''Do some stuff to the data being passed to my function and return a bunch of variables to be printed ''' def functionThree(self, data): '''Do some stuff to the data being passed to my function and return a bunch of variables to be printed ''' def functionFour(self, data): '''Do some stuff to the data being passed to my function and return a bunch of variables to be printed ''' if __name__ == ('__main__'): MainClass()

1 个答案:

答案 0 :(得分:0)

  

我的问题是使用两者的可能含义是什么   OperationalContract和WebInvoke,如果有的话?有缺点吗?

不,除了添加可能永远不会使用的代码之外,没有任何缺点。

此外,对于您的信息,OperationContract适用于所有WCF操作,而不仅仅适用于SOAP操作。你也需要它用于REST。