WSDL 最佳实践 [英] WSDL best practices

查看:45
本文介绍了WSDL 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个与第三方集成的 SOAP 应用程序.我觉得这个第三方的 WSDL 很奇怪.我对 SOAP 很陌生,所以如果它没有损坏,我不想去要求他们修复它.以下是我注意到的一些我认为错误的事情,尽管我确信它在技术上是有效的文档(因此我在标题中写下了最佳实践").另外,我使用 gSOAP 作为我的 SOAP 库,这可能就是我认为其中一些东西很奇怪的原因(我对 gSOAP 的了解甚至比我对 SOAP 的了解还新).

I'm developing a SOAP application that integrates with a 3rd party. I think the WSDL of this third party is very strange. I'm pretty new to SOAP, so I don't want to go asking them to fix it if it isn't broken. Here's some things I've noticed that I consider wrong about it, though I'm sure it's technically a valid document (hence the reason I wrote "best practices" in the title). Also, I'm using gSOAP as my SOAP library, which may be why I think some of these things are weird (I'm even newer to gSOAP than I am to SOAP in general).

  1. 它们在同一 WSDL 中为 SOAP 1.1 和 SOAP 1.2 指定了接口.这会导致 gSOAP 生成两倍于它需要的类,因为我将只使用 1.2.

  1. they have interfaces specified for both SOAP 1.1 and SOAP 1.2 in the same WSDL. This causes gSOAP to generate twice as many classes as it needs to, since I'm only going to use 1.2.

他们所有的命名空间都是 http://tempuri.org.不应该是那样的吧?

all of their namespaces are http://tempuri.org. That shouldn't be like that, right?

尽管定义了一堆 RPC 调用,但它们的 WSDL 使用文档格式.我正在考虑要求他们切换到 RPC 格式,因为 gSOAP 似乎不会生成采用 C++ 类型参数作为文档格式的方法.相反,它为每个 API 函数的输入和响应数据创建一个新类.如果我不能解决这个问题,我将不得不编写另一层围绕 gSOAP 的东西来为我的应用程序的其余部分提供合理的 API.另外,AFAICT,如果他们切换到RPC,将来回的XML将与现在完全相同,所以我认为这并不困难.

despite defining a bunch of RPC calls, their WSDL uses the document format. I'm thinking of asking them to switch to RPC format because it seems that gSOAP won't generate methods that take C++ typed parameters for document format. Instead, it creates a new class for every API function's input and response data. I'll have to write another layer of wrapping around the gSOAP stuff to provide a reasonable API to the rest of my app if I can't fix that. Also, AFAICT, the XML that will be going back and forth would be exactly the same as it is now if they switched to RPC, so I don't think it would be difficult.

元素的 minOccurs = 0 但当我提交没有它们的请求时,我得到返回的错误指示它们是必需的(有时甚至是空指针异常的堆栈跟踪).如果需要,他们应该将它们指定为 minOccurs = 1,对吗?

elements have minOccurs = 0 yet when I submit requests without them, I get errors returned back indicating they're required (sometimes even stack traces of null pointer exceptions). They should specify them as minOccurs = 1 if they're required, right?

几乎所有的 Web 服务函数都指定了一个响应,其中包含一个表示成功的整数(实际上是一个布尔值)和一个错误消息字符串.他们应该为此使用 SOAP 错误吗?我认为如果它是一个错误,我的应用程序会更容易处理,因为 gSOAP 可以让我很容易地解决这个问题(并简单地打印错误消息).

nearly all of the web service functions specify a response that includes an integer to indicate success (really a boolean) and an error message string. Should they be using SOAP faults for this? I think it would be easier for my application to handle if it was a fault since gSOAP will let me figure that out really easily (and print the error message trivially).

当然,我对这家 3rd 方公司会因为我要求他们改变他们的 WSDL 抱有很高的期望.至少我会学到一些东西……就我所知,这些都没有错,甚至没有问题.感谢您的帮助.

Of course, I don't have high hopes that this 3rd party company will change their WSDL just because I've asked them to. At least I'll learn something... for all I know, none of these are wrong or even questionable. Thanks for your help.

推荐答案

1 - 他们可能认为这是一个功能.:-)

1 - They probably consider this a feature. :-)

2 - 这太可怕了.

3 - 很多人推荐这个.它被称为包装格式.

3 - Lots of people recommend this. It's called wrapped format.

4 - 你是对的.

5 - 视情况而定.理论上,您可能是对的,但实际上很多 SOAP 工具包都没有很好地支持 SOAP 错误,因此它们可能故意选择不使用异常.

5 - It depends. Theoretically, you're probably correct, but in practice lots of SOAP toolkits don't have very good support for SOAP faults, so they might have deliberately chosen to not use exceptions.

这篇关于WSDL 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆