使用 WCF,REST 和 SOAP 肯定应该协调工作吗?
REST 只接受字符串..?
所以我所做的就是制作一个字符串公开合同并将其转换为服务器端,然后将其传递给 SOAP 直接调用的方法。这有效。 (我可以从 firefox 调用 REST)
但是现在,我无法在不导致错误问题的情况下公开我的 SOAP OperationContract:
Operation 'GetServices' of contract 'IServices' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
以下是我公开的 3 个方法。 只有当我隐藏第三个方法时,REST 才会起作用。 删除我的 SOAP 连接..(我相信它需要在第三个方法上进行 REST 设置,并且由于它尚未定义,因此无法理解它)
// REST
[OperationContract]
[WebGet(UriTemplate = "GET/Services/{CostCentreNo}/{Filter}")]
List<Services> RestGetServices(String CostCentreNo, String Filter);
// REST
[OperationContract]
[WebGet(UriTemplate = "GET/ServiceDetails/{CostCentreNo}/{ServiceCode}/{Recurring}")]
List<ServiceDetails> RestGetServiceDetails(String CostCentreNo, String ServiceCode, String Recurring);
// SOAP
[OperationContract]
List<Services> GetServices(Int32 CostCentreNo, Int32 Filter);
我当然可以只有一种契约方法,它允许我调用 SOAP 或 REST。
REST Only accepts String..?
So What I do is make a string exposed contract and convert it server side, and pass it to my method which SOAP was directly calling. Which works. ( I can call REST from firefox)
BUT now, I cannot expose my SOAP OperationContract with out causing a problem with the error:
Operation 'GetServices' of contract 'IServices' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
Below are my 3 exposed methods. Only when I hide the 3rd will REST work. Removing my SOAP connection.. ( I belive it wants REST setup on the 3rd method and as its not been defined, fails to understand it)
// REST
[OperationContract]
[WebGet(UriTemplate = "GET/Services/{CostCentreNo}/{Filter}")]
List<Services> RestGetServices(String CostCentreNo, String Filter);
// REST
[OperationContract]
[WebGet(UriTemplate = "GET/ServiceDetails/{CostCentreNo}/{ServiceCode}/{Recurring}")]
List<ServiceDetails> RestGetServiceDetails(String CostCentreNo, String ServiceCode, String Recurring);
// SOAP
[OperationContract]
List<Services> GetServices(Int32 CostCentreNo, Int32 Filter);
Surely I can make just one contract method, which allows me to call either SOAP OR REST.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 我可以将非字符串传递给使用 UriTemplate 的 WCF RESTful 服务?:
这取自答案( 我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?),粗体格式是我的...
因此,REST 和 SOAP 可访问方法的示例:
可通过以下方式访问:
http://localhost:1337/WCF.IService.svc/rest/Services?CostCentreNo=1&Filter=1
As mentioned in Can I pass non-string to WCF RESTful service using UriTemplate? :
This is taken from the answer ( Can I pass non-string to WCF RESTful service using UriTemplate? ), bold formatting is mine...
So an example of a REST and SOAP accessable method:
Which is accessible by
http://localhost:1337/WCF.IService.svc/rest/Services?CostCentreNo=1&Filter=1
不正确的字符串 No。映射到 URL 模板的参数可以是任何基本类型。 WCF将为您进行转换。如果您使用
WebInvoke
而不是WebGet
并且您将使用 PUT 或 POST 方法,您甚至可以在请求中传递整个可序列化对象。No that is not true. Parameters mapped to URL template can be any basic type. WCF will make conversion for you. If you use
WebInvoke
instead ofWebGet
and you will use PUT or POST method you can even pass whole serializable objects inside requests.