小编Ale*_*exS的帖子

JAX-WS始终以内联方式发送MTOM附件

基本上我想创建一个Web服务客户端,通过代理方法发送一个mtom soap消息.我已经从Web服务wsdl创建了我的服务工件.消息是正确创建的,但是当我启用mtom并添加附件时,附件始终是内联发送的,而不是单独的mime部分.它像mtom一样启用但由于某种原因它决定不优化消息,因此将其发送到内联.通过soapui运行相同的代码会得到正确的结果,所以我知道服务本身会接受它.

这是我创建soap请求并发送它的基本代码.我启用了mtomfeature,但也尝试过这样做.soapBinding.setMTOMEnabled(true); 对于我调试它的两种方法((SOAPBinding) binding).isMTOMEnabled(),检查它是否设置为启用.

// initiate services....

// create service and enable mtom
WebServiceBlah service = new WebServiceBlah(new URL(wsdlURL), SERVICE_NAME);
WebServiceBlahPort port = service.getWebServiceBlahPort(new MTOMFeature(true, 3072));

// load file
File file = new File("/home/mypdf.pdf");
FileInputStream fileinputstream = new FileInputStream(file);
int numberBytes = fileinputstream.available();
byte bytearray[] = new byte[numberBytes];
fileinputstream.read(bytearray);
fileinputstream.close();

// create uploadResult
UploadResult request = new UploadResult();

// create attachment
AttachmentType attachment = new AttachmentType();
attachment.setContentType("application/doc");
attachment.setValue(bytearray);

// create result and add attachment to it …
Run Code Online (Sandbox Code Playgroud)

java client soap web-services mtom

10
推荐指数
1
解决办法
6447
查看次数

标签 统计

client ×1

java ×1

mtom ×1

soap ×1

web-services ×1