SOAP: 簡(jiǎn)單對(duì)象訪問協(xié)議(Simple Object Access Protocol), 是一種輕量的、簡(jiǎn)單的、基于 XML 的協(xié)議, 它被設(shè)計(jì)成在 Web 上交換結(jié)構(gòu)化的和固化的信息. SOAP 可以和現(xiàn)存的許多因特網(wǎng)協(xié)議和格式結(jié)合使用, 包括 HTTP, SMTP, MIME. 它還支持從消息系統(tǒng)到遠(yuǎn)程過程調(diào)用(RPC)等大量的應(yīng)用程序.
Suds is a lightweight SOAP python client for consuming Web Services.
sudo easy_install suds
示例調(diào)用短信發(fā)送接口,java, XFire, SOAP WSDL, webservice
#!/usr/bin/python#import logginglogging.basicConfig(level=logging.INFO) from suds.client import Clientfrom suds.sax.element import Element url = 'http://localhost:8080/SendSmsService?wsdl'client = Client(url) # custum soap headers for authenticationauth = Element('AuthenticationToken') system = Element('system').setText('SMS')auth.append(system)username = Element('username').setText('sms')auth.append(username)password = Element('password').setText('sms')auth.append(password)client.set_options(soapheaders=auth) client.service.sendSms('13912345678', 'python soap client through java soap server')
Soaplib is an easy to use python library for publishing soap web services using WSDL 1.1 standard, and answering SOAP 1.1 requests. With a very small amount of code, soaplib allows you to write a useful web service and deploy it as a WSGI application. WSGI is a python web standard for writing portable, extendable web applications in python.
sudo easy_install soaplib
PHP的soap擴(kuò)展不支持自定義頭的認(rèn)證方式,不過可以通過自定義請(qǐng)求XML文件的方式來實(shí)現(xiàn)。以下文件需要PHP的soap擴(kuò)展,請(qǐng)先安裝后再運(yùn)行。
$wsdl = 'http://localhost:8080/services/SendSmsService?wsdl'; $client = new SoapClient($wsdl); $reqXml = <<<XML<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0="http://sendSms.webservice.com" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header> <AuthenticationToken> <system>SMS</system> <username>sms</username> <password>sms</password> </AuthenticationToken> </SOAP-ENV:Header> <ns1:Body> <ns0:sendSms> <ns0:in0>%s</ns0:in0> <ns0:in1>%s</ns0:in1> <ns0:in2>1</ns0:in2> </ns0:sendSms> </ns1:Body></SOAP-ENV:Envelope>XML; $req = sprintf($reqXml, '13912345678', 'php soap client through java soap server'); $location = 'http://localhost:8080/services/SendSmsService'; $action = 'sendSms'; $result = $client->__doRequest($req, $location, $action, SOAP_1_1);
聯(lián)系客服