我在項目上使用Axis 1.4,我正在轉向Axis2 1.6.3。我因爲在Axis1.4問這是很簡單:如何使用Axis2將二進制文件發送到Web服務?
myStub.addAttachment(new DataHandler(new FileDataSource("path_to_file")));
您只需添加一個的DataHandler的存根,然後將其發送。但在Axis2似乎這種方法不存在。所以我想知道將DataHandler附加到存根的新方法是什麼?
當我在網上搜索時,我發現你必須將DataHandler附加到MessageContext
(Downloading a Binary File from a Web Service using Axis2 and SOAP with Attachments)。
所以我照它說:
MessageContext messageContext = MessageContext.getCurrentMessageContext();
OperationContext operationContext = messageContext.getOperationContext();
MessageContext outMessageContext = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
outMessageContext.addAttachment(new DataHandler(new FileDataSource("path_to_file")));
但問題是,MessageContext.getCurrentMessageContext()
返回NULL。我認爲它不起作用,因爲這個片段應該在服務器端使用。我想要的是能夠將文件發送到服務器,而不是從服務器中檢索一個文件。
我可能會錯過一些東西。也許這不是這樣做,無論如何,任何幫助表示讚賞。在此期間,我會繼續在互聯網上搜索,如果我找到了一些我會讓你知道:)