Make SOAP request in Go

huangapple go评论59阅读模式
英文:

Make SOAP request in Go

问题

我在Stack Overflow上看到了几个类似的问题,但它们都比较旧/可能已过时,所以我想知道是否有任何新的包或方法可以在Go中进行SOAP请求。谢谢!

英文:

I've seen several other similar questions on Stack Overflow, but they're fairly old / potentially outdated so I'm wondering if there's any new packages or methods for making SOAP requests in Go. Thanks!

答案1

得分: 2

我认为没有。

首先,有两个描述SOAP的文档,一个是所谓的“SOAP Note”,它虽然不是官方标准,但被广泛称为“SOAP 1.0”,另一个是真正的标准,通常称为SOAP 1.1。尽管它们在外观上看起来相同,但它们并不兼容。

另一方面,SOAP本身作为客户端发送和服务器响应的XML编码是简单的,实际上,编写一个简单的SOAP包装器(用于进行客户端调用)和解包装器(用于解封服务器的响应)也是简单的。

我想强调的是:两个SOAP标准实际上并不涉及HTTP,因为SOAP明确定义为与传输无关(因此它遇到了与ReST范式相同的问题:每个人都认为它与HTTP有关),而Go的标准库对HTTP有出色的支持,因此SOAP的编码/解码层似乎相当薄。

基于这些考虑,就我个人而言,每当我需要通过SOAP调用某些内容并编写必要的代码时,我甚至都不会费心依赖第三方的SOAP包;我只是检查了一下,上次我需要进行SOAP 1.2调用时,SOAP编码器/解码器最终只需171行Go代码(不包括测试)。

所以我会建议你自己动手。

不过要注意,只有在你的服务器不需要使用一些奇怪的东西时,这一切才是如此简单——例如那可怕的WS-Security扩展,它要求以特定的XML格式发送数据,计算其上的加密哈希值,对其进行数字签名等等;目前在Go中还没有处理这些问题的方法。

同样的情况也适用于WSDL规范或XSD模式。据我了解,目前还没有足够高质量的工具可以根据WSDL文档或XSD模式为您生成类型层次结构和SOAP端点客户端存根。

英文:

I think there are none.

To begin with, there are two documents describing soap—the so-called "SOAP Note" which is officially not a standard but is widely referred to as "SOAP 1.0", and another one, which is the standard and is commonly referred to as SOAP 1.1. They are not compatible even though they look superficially the same.

On the other hand, SOAP itself—as XML encoding of what
the client sends, and what the server responds with—is simple,
and in fact crafting a simple SOAP wrapper (to make client calls) and
unwrapper (to decapsulate server's responses) is simple.

I'd like to stress this: both SOAP standards do not actually deal with
HTTP as SOAP is explicitly defined to be transport-agnostic
(it hence suffers from the same problem the ReST paradigm does: everyone
thinks it's about HTTP), and the Go's standard library features excellent
support for HTTP, so the SOAP encoding/decoding layer appears to be rather
thin.

With these considerations, I, personally, did not even bother to start
depending on a 3rd-party package for SOAP in each of the cases I needed to
call something over SOAP and wrote the necessary code myself;
I've just checked that the last time I needed
to do SOAP 1.2 calls, the SOAP encoder/decoder ended up being 171 lines
of Go code (excluding tests).

So I'd say just roll your own.

Note though that it's all that simple only if your server does not require
something awry to use—for instance that dreaded WS-Security extension
which requires special formatting of XML to be sent,
calculating cryptographic hashes over it, digitally signing them
and all such stuff; there's just nothing to handle this in Go as of yet.

The same applies so WSDL specs or XSD schemas.
IIUC, there presently is no tools of sufficient quality which would generate
type hierarchies and SOAP endpoint client stubs for you given a WSDL
document or an XSD schema.

huangapple
  • 本文由 发表于 2017年2月24日 12:38:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/42430892.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定