我正在尝试为Celltrust的短信网关设置一个网络服务。我有他们的SDK,我正在尝试使用soap4r来创建它需要的自定义标头。我不确定我需要做什么才能以它们的格式获取它,因为它们没有向我提供显示它们所需内容的实际XML文档;他们所说的只是在标题中你需要提供一个用户名和密码。
鉴于以下PHP示例代码,我将如何在Ruby中执行此操作?
$URN = "urn:notify.soap.primemessage.com";
$WSDL="http://pmgateway.net/pmws/services/TxTMessageService?wsdl";
//SOAP elements (don’t edit, and case sensitive!)
$CTUSERNAME = "Username";
$CTPASSWORD = "Password";
$CTNICKNAME = "nickname";
$DESTINATION = "destination";
$MESSAGE = "message";
$USER_ID = "USERNAME"; //your username at CellTrust
$NICKNAME = "NICKNAME"; //your nickname at Celltrust
$PASSWORD = "PASSWORD"; //your password at Celltrust
//create user and password SOAP header elements
$UserHdr = new SoapHeader( $URN, $CTUSERNAME, $USER_ID, false);
$PassHdr = new SoapHeader( $URN, $CTPASSWORD, $PASSWORD, false);
// call the method here
我创建了SOAP :: Header :: SimpleHandler的派生类。我不确定的是我是否需要指定名称空间两次(一次是Username,一次是Password)或者是如何生成它。该文档没有给出命名空间的任何名称,我不确定如何正确地在Ruby中调用“new SoapHeader”。
任何人都可以帮我吗?
答案 0 :(得分:0)
您需要创建一个SOAP :: Header :: SimpleHandler的子类,如下所示:
class MyHandler < SOAP::Header::SimpleHandler
def initialize(namespace, name, value)
super(XSD::QName.new(namespace, name))
@value = value
end
def on_simple_outbound
@value
end
end
然后就这样做:
namespace = 'INSERT_NAMESPACE_URL_HERE'
# 'driver' below is the Soap4R driver for the service
driver.headerhandler << MyHandler.new(namespace, 'Username', 'INSERT_USERNAME_HERE')
driver.headerhandler << MyHandler.new(namespace, 'Password', 'INSERT_PASSWORD_HERE')