有 gSOAP 的轻量级替代品吗?
我尝试使用 gSOAP 访问 Web 服务(例如,使用提供的 WSDL 生成 C 存根,然后在应用程序中使用它们)。但是,我发现生成的 .c 和目标文件相当大(几兆字节),这在我工作的嵌入式环境中是一个问题。
您是否知道任何更简单的 SOAP 库,或者我是否必须使用通用 XML 生成器和解析器(如 ezXML)?
I've tried using gSOAP for accessing a web service (e.g. using supplied WSDL to generate C stubs and then using them in an app). However, I've found that the generated .c and object files is quite big (several megabytes), which is a problem in embedded environment where I work.
Do you know of any simpler SOAP libraries, or do I have to fall back to generic XML generators and parsers like ezXML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最近也研究了这个问题,我发现最好的选择是 gSOAP,它非常成熟并且经过了良好的测试。然而,我决定采用非 SOAP 路线,这是一个选项,因为我既在客户端又在服务器端。在使用 gSOAP 之前,请确保您可以接受他们的许可证,您可能有义务发布您的代码或向他们付费,具体取决于您如何使用它。
另一个选择是 Apache Axis2/C,尽管我没有使用它的经验(我猜它的占地面积与 gSOAP 相似)。他们的客户端 API 位于此处。有关客户端 API 的教程位于此处。
如果您决定采用解析的 XML 路线,您可能会对这个 SO问题感兴趣(请参阅答案)。
您还可以检查 boost::spirit 来获取已解析的路由。如果您熟悉 C++,它有能力制作小型、快速、专用(和通用)解析器(它们可以编写为可重入的,因此通过具有外部“C”接口的静态对象调用它们是合理的)。我可以在一般意义上保证这一点(不是特定于 XML)。学习曲线陡峭,但回报丰厚。
I recently looked into this question too, and the best option I found was gSOAP, it is very mature and well tested. However, I decided to go a non-SOAP route, which was an option since I'm on both client and server sides. Before using gSOAP, make sure you can live with their license, you may be obliged to release your code or pay them, depending how you use it.
Another option is Apache Axis2/C, though I have no experience with it (I would guess that it has a similar sized footprint to gSOAP). Their client API is here. A tutorial on the client API is here.
If you decide to go the parsed XML route, you might be interested in this SO question (see answers).
You might also checkout boost::spirit for the parsed route. It has the ability to make small, fast, specialized (and general) parsers, if you're comfortable with C++ (they can be written to be reentrant, so a calling them through a static object with an extern "C" interface is kosher). I can vouch for it in the general sense (not specific to XML). Steep learning curve, but big payoff.
这是您正在创建的 Web 服务吗?如果是这样,请考虑使用 REST 而不是 SOAP。 REST 要简单得多,您可以使用现有的、经过测试的、正在运行的 HTTP 处理程序,而不是通过庞大的 HTTP - XML - SOAP 转换层。
如果您正在使用其他人的 Web 服务,请检查 SOAP 架构和/或响应示例。我不敢相信我在提倡这一点,但如果模式不可扩展或递归,您可能最好使用简单的 LALR 解析器,甚至在原始 HTTP 响应中进行字符串匹配,而不是尝试解析 SOAP 或 XML。这在嵌入式 C 语言中实现起来要简单得多。
Is this a web service that you are creating? If so, consider using REST instead of SOAP. REST is far simpler, and you can use existing, tested, working now HTTP handlers instead of going through a huge HTTP - XML - SOAP translation layer.
If you are consuming someone else's web service, examine the SOAP schema and/or examples of responses. I cannot believe I am advocating this, but if the schema is not extensible or recursive, you may be better off using a simple LALR parser or even string matching in the raw HTTP responses instead of trying to parse SOAP or XML at all. This is far simpler to implement in embedded C.
通常我们会退回到直接创建 XML(主要是通过字符串连接),因为没有好的 SOAP 库可以使用。
另一个解决方案可能是切换到 JSON,它(通常)具有较小的开销和请求/响应大小,因此它在嵌入式程序中可能更好。如果您只有可用的 SOAP WebService,则可以在服务器上使用代理脚本,将 JSON 请求转换为 SOAP 请求,并将 SOAP 响应转换为 JSON 响应。
Usually we fall back to creating the XML directly (mostly by string concatenation) where no good SOAP library can be used.
Another solution could be that you switch to JSON, which (usually) has smaller overhead and request/response sizes so it could be better in embedded programs. If you only have a SOAP WebService available you could use a proxy Script on the Server which translates JSON Requests to SOAP Requests and SOAP Responses to JSON Responses.
您看过 Apache CXF 吗?它有几个代码生成功能
构建消费者的更有用的指南是 这里。
Have you looked at Apache CXF. It has several code gen features
A more helpful guide to build a consumer is here.