你会自定义SOAP头消息吗?

先请大家看一篇文章:Get a Handle on SOAP Headers
http://www.aspnetpro.com/features/2002/10/asp200210dw_f/asp200210dw_f.asp

通过这篇文章,大家可以学习到在.Net环境下如何获取对SOAP消息头的操作,并对SOAP消息进行自定义,加进自己的功能!这在开发涉及安全、身份认证、附件传输等Web Services的时候非常有用!由于时间关系,我没来得及翻译,见谅!

作者在例程中自定义了一个标记authenticationtoken来存放唯一标识注册用户身份的信息,通过对一个从SoapHeader继承下来的类AuthenticationHeader的处理,将标记信息添加到用户向服务器提交的SOAP认证消息的头部,形成了如下的消息格式:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="htt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 SOAP 中添加自定义信息,你需要使用 SOAP 处理程序(SOAP Header Handler)来实现。在 C++ 中,可以通过以下步骤来实现: 1. 创建一个 SOAP 处理程序类,继承自 gsoapsoap_header 类。 2. 在类中添加要添加到 SOAP 中的自定义信息字段。 3. 实现 soap_header 类的 virtual 函数,用于在 SOAP 消息中添加自定义信息。 4. 在 gsoap 生成的客户端或服务端代码中,使用 soap_register_plugin() 函数注册 SOAP 处理程序。 下面是一个简单的示例代码,用于在 SOAP 中添加自定义信息: ```c++ #include "soapH.h" class MySoapHeader : public soap_header { public: int myCustomField; MySoapHeader() : myCustomField(0) {} virtual int put(struct soap *soap, const char *tag, int id, void *ptr, size_t len) { if (strcmp(tag, "MyCustomField") == 0) { soap_element(soap, "MyCustomField", &myCustomField, sizeof(myCustomField), XSD_INT); return SOAP_OK; } return soap_header::put(soap, tag, id, ptr, len); } }; int main() { struct soap soap; soap_init(&soap); // 创建 SOAP 处理程序 MySoapHeader header; header.myCustomField = 123; // 注册 SOAP 处理程序 soap_register_plugin(&soap, &header); // 发送 SOAP 消息 // ... soap_destroy(&soap); soap_end(&soap); soap_done(&soap); return 0; } ``` 在上面的代码中,MySoapHeader 类继承自 soap_header 类,添加了一个名为 myCustomField 的自定义字段。在 put() 函数中,如果 SOAP 消息中的标签为 "MyCustomField",则将 MyCustomField 字段添加到 SOAP 消息中。最后,在 main() 函数中,创建了一个 MySoapHeader 实例并注册到 soap 对象中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值