此服務(wù)的WSDL顯示如下。注意,它使用了一個(gè)標(biāo)準(zhǔn)的SOAP/HTTP綁定,并且使這個(gè)服務(wù)端點(diǎn)在URL中是可用的。
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions ...> <wsdl:types> ... <wsdl:portType name="Calculator"> <wsdl:operation name="multiply"> <wsdl:input message="intf:multiplyRequest"name="multiplyRequest"/> <wsdl:output message="intf:multiplyResponse" name="multiplyResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CalculatorSoapBinding" type="intf:Calculator"> <wsaw:UsingAddressing wsdl:required="false" xmlns:wsaw="http://www.w3.org/2006/02/addressing/wsdl"/> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="multiply"> <wsdlsoap:operation soapAction="multiply"/> ... </wsdl:operation> </wsdl:binding> <wsdl:service name="CalculatorService"> <wsdl:port binding="intf:CalculatorSoapBinding" name="Calculator"> <wsdlsoap:address location="http://localhost:9080/WSUTSigEncRouterWeb/services/Calculator"/> </wsdl:port> </wsdl:service> </wsdl:definitions> |
在此示例中,使用Xfire stub生成器從WSDL創(chuàng)建CalculatorServiceClient。下面的代碼使用這個(gè)stub來(lái)調(diào)用web服務(wù)的乘法方法,并將參數(shù)5和7傳遞給它:
package com.dev.ws.client.calculator.driver; ... public class WSClientUTSigEnc { // Non-SSL URL public static String UT_ENDPOINT = "http://localhost:9080/WSUTSigEncRouterWeb/services/Calculator"; public static void main(String[] args) throws MalformedURLException { CalculatorServiceClient sc = new CalculatorServiceClient(); Calculator calc = sc.getCalculator(UT_ENDPOINT); float a = 5f; float b = 7f; System.out.println(a + " * " + b + " = " + calc.multiply(a,b)); } After starting the server and running the client, you can use a TCP/IP monitor at port 9080 to observe the messages that the client sends to the web service. You should observe a SOAP message that looks like this: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <multiply xmlns="http://ejb.security.ws.dev.com"> <a>5.0</a> <b>7.0</b> </multiply> </soap:Body> </soap:Envelope> The client outputs the expected result after getting the SOAP response: 5.0 * 7.0 = 35.0 |
上面的SOAP消息只是簡(jiǎn)單地將方法請(qǐng)求包含進(jìn)來(lái),并沒(méi)有安全的報(bào)頭。為了在SOAP消息的級(jí)別上支持加密,應(yīng)用程序服務(wù)器和客戶端必須加以配置來(lái)支持XML加密?蛻舳藦囊粋(gè)X509的證書(shū)使用一個(gè)公鑰來(lái)對(duì)SOAP消息加密,而服務(wù)器相對(duì)應(yīng)地使用私鑰對(duì)此消息解密。一對(duì)公/私鑰必須由給客戶端的公鑰和給服務(wù)器的私鑰來(lái)生成。(可參考如下的XFire文章來(lái)查看如何創(chuàng)建這對(duì)密鑰的相關(guān)細(xì)節(jié)信息。應(yīng)用程序服務(wù)器的配置與服務(wù)器息息相關(guān),因此請(qǐng)參考你的服務(wù)器的相關(guān)文檔資料,以得到XML加密的用法說(shuō)明。你可以在這里找到本文的WebSphere配置的相關(guān)指導(dǎo)。)
加密過(guò)程
在XFire框架中,你使用處理程序來(lái)處理客戶端的SOAP消息。每一個(gè)處理程序接受一套屬性,這些屬性可以規(guī)定WSS4J必須實(shí)施的消息安全性。為了執(zhí)行加密,你必須為以下的幾個(gè)方面規(guī)定屬性:
客戶端公鑰的存儲(chǔ)位置
加密的運(yùn)行法則
本新聞共
6頁(yè),當(dāng)前在第
2頁(yè)
1 2 3 4 5 6