通过JAX-WS 2.1,你能够发送binary data 在基于soap 的webservice application 中。它有两种方式来反送binary data.
1.直接发送encoded的binary data 在soap请求的body中。
2.把binary data 作为soap body的一个附件来发送
第一种发送方式的优点是比较通用,它适用于任何传输协议(SOAP,/HTTP, SOAP/JMS, and so on),但是它有一个弊端就是这些要传输的binarydata 会被JAX-WS 2.1 使用base64 encoded.这将会导致要传输的soap Message 变的很大,导致严重的性能问题。
实例代码如下:
Service Class
package itso.hello;
import javax.jws.WebService;
@WebService
public class HelloBinaryMessenger {
public byte[] sayHello(byte[] nameAsBytes) {
return String.format("Hello %s", new
String(nameAsBytes)).getBytes();
}
}
Client 端class
public class HelloBinaryClient {
public static void main(String... args) throws Exception {
HelloBinaryMessengerService service = new
HelloBinaryMessengerService();
112 IBM WebSphere Application Server V7.0 Web Services Guide
HelloBinaryMessenger port =
service.getHelloBinaryMessengerPort();
byte[] message = port.sayHello( "Milo".getBytes() );
System.out.println( new String(message) );
生成的soap request 跟soap response如下
<!-- SOAP Request Envelope -->
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHello xmlns:ns2="http://hello.itso/">
<arg0>TWlsbw==</arg0>
</ns2:sayHello>
</S:Body>
</S:Envelope>
<!-- SOAP Response Envelope -->
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHelloResponse xmlns:ns2="http://hello.itso/">
<return>SGVsbG8gTWlsbw==</return>
</ns2:sayHelloResponse>
</S:Body>
</S:Envelope>
如果你使用第二种方式的化,被传输的binary data 不会被encode,JAX-WS 2.1会使用MTOM(Message Transport optimize Mechanism)机制来自动处理attachment.你所要做的就是在service 端跟client 端启用MTOM.当然这种传输方式要求run times要支持SOAP 1.1/HTTP 或者SOAP 1.2/HTTP.
示例代码如下:
Server端启用MTOM,Binding Type 设成SOAPBinding.SOAP11HTTP_MTOM_BINDING:
@WebService
//Binding Type 设成SOAPBinding.SOAP11HTTP_MTOM_BINDING
@BindingType(value=SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class HelloBinaryMessenger {
public byte[] sayHello(byte[] nameAsBytes) {
return String.format("Hello %s", new
String(nameAsBytes)).getBytes();
}
}
Client端启用Enable MTOM:
SOAPBinding soapBinding = (SOAPBinding)
bindingProvider.getBinding();
soapBinding.setMTOMEnabled(true);
public class HelloBinaryClient {
public static void main(String... args) throws Exception {
HelloBinaryMessengerService service = new
HelloBinaryMessengerService();
HelloBinaryMessenger port =
service.getHelloBinaryMessengerPort();
BindingProvider bindingProvider = (BindingProvider) port;
SOAPBinding soapBinding = (SOAPBinding)
bindingProvider.getBinding();
soapBinding.setMTOMEnabled(true);
byte[] message = port.sayHello( "Milo".getBytes() );
System.out.println( new String(message) );
分享到:
相关推荐
Hessian Binary Web Service Protocol远程接口调用入门Demo例子!
IndexingService_Binary.zip IndexingService_Binary.zip
This book provides a comprehensive introduction to Jersey framework (an implementation of JAX-RS specification) as the application development framework for RESTFul web service development. This book ...
Exporting Context Data into Excel Using the WebDynpro Binary Cache.pdf
amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gzamoeba-mysql-binary-2.2.0.tar.gz amoeba-mysql-binary-2.2.0.tar.gz ...
集成chrome 内核收集到的 cef_binary , 包含cef 1x,2x,41,43 版本。 具体看 https://www.spotify.com/sg-en/opensource/ cef 对应 chrome版本 cef_binary_3.2357.1271.g8e0674e_windows32 cef_binary_3....
Indicator Metatrader 4 binary option
ELF Format,Binary Analysis Fundamentals,Basic Binary Analysis in Linux,Disassembly and Binary Analysis Fundamentals
excelent indicator for binary option 85 winn
深圳证券交易所binary行情协议说明,行情网关marketdata接收指导
binary64.bin
最小成本二分检索树optimal binary optimal binary
binaryClassification
Learning Linux Binary Analysis is packed with knowledge and code that will teach you the inner workings of the ELF format, and the methods used by hackers and security analysts for virus analysis, ...
AjaxControlToolkit.Binary.NET4AjaxControlToolkit.Binary.NET4AjaxControlToolkit.Binary.NET4AjaxControlToolkit.Binary.NET4AjaxControlToolkit.Binary.NET4AjaxControlToolkit.Binary.NET4AjaxControlToolkit....
xml binary soap 三种序列化反序列化
binary tree 的C语言实现算法,需要在linux环境下编译
A binary search algorithm (or binary chop) is a technique for finding a particular value in a sorted list. It makes progressively better guesses, and closes in on the sought value, by comparing an ...
NPOI文件2.21版,轻松操作Excel, 请各位下载使用,谢谢大家。NPOI 2.2.1 binary package.zip
60秒二位權交易系統 Binary Option Trading System