使用 WCF,REST 和 SOAP 肯定应该协调工作吗?

发布于 2024-12-07 08:07:56 字数 1245 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朦胧时间 2024-12-14 08:07:56

正如 我可以将非字符串传递给使用 UriTemplate 的 WCF RESTful 服务?

路径中的 UriTemplate 变量在使用时始终解析为字符串
WebGet 或 WebInvoke。您只能将 UriTemplate 变量绑定到 int,
long 等,当它们位于 UriTemplate 的 query 部分时。

这取自答案( 我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?),粗体格式是我的...

因此,REST 和 SOAP 可访问方法的示例:

// REST AND SOAP
[OperationContract]
[WebGet(UriTemplate = "/Services?CostCentreNo={CostCentreNo}&Filter={Filter}")]
List<Services> GetServices(Int32 CostCentreNo, Int32 Filter);

可通过以下方式访问:

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? :

UriTemplate variables in the path always resolve to strings when using
WebGet or WebInvoke. You can only bind UriTemplate variables to int,
long, etc. when they are in the query portion of the 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:

// REST AND SOAP
[OperationContract]
[WebGet(UriTemplate = "/Services?CostCentreNo={CostCentreNo}&Filter={Filter}")]
List<Services> GetServices(Int32 CostCentreNo, Int32 Filter);

Which is accessible by

http://localhost:1337/WCF.IService.svc/rest/Services?CostCentreNo=1&Filter=1

别想她 2024-12-14 08:07:56

REST 只接受字符串

不正确的字符串 No。映射到 URL 模板的参数可以是任何基本类型。 WCF将为您进行转换。如果您使用 WebInvoke 而不是 WebGet 并且您将使用 PUT 或 POST 方法,您甚至可以在请求中传递整个可序列化对象。

REST only accepts string

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 of WebGet and you will use PUT or POST method you can even pass whole serializable objects inside requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文