Get your CodeRanch badge!*
The moose likes Web Services and the fly likes Need Help in passing a string as a attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Need Help in passing a string as a attachment" Watch "Need Help in passing a string as a attachment" New topic
Author

Need Help in passing a string as a attachment

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 556
I am trying to pass a string as a attachment, but when I examine what is being sent it looks as if the string is being passed in the Body.

According to weblogic :
Certain Java data types, if used as parameters or return values of a method that implements a Web Service operation, are automatically transported as SOAP Attachments (rather than elements in the SOAP body) when going over the wire.

As I understand it this means passing a parameter as a datahandler.

Here is my code snippet

String attachement = attach.getAttachments().toString();
StringDataSource sds = new StringDataSource(attachement,"String","Attachment");

DataHandler dh = new DataHandler(sds);
Results res = new Results();

//The remote soap call.
port.scanForViruses(dh);

I have created a DataHandler and am passing it as a parameter, as laid down in weblogic.

I have set up a sniffer, but not sure what I should be looking for to say it has been passed as a Attachement:
Here is the sniffer output:

------ 10.101.193.171:11001->localhost:3669 ------
HTTP/1.1 200 OK
Date: Thu, 08 Jun 2006 09:53:52 GMT
Content-Length: 2338
Content-Type: text/xml
Connection: Keep-Alive

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:tns="http://www.inlandrevenue.gov.uk/schemas/AntiVirusSoapService"
xmlns:wsr="http://www.openuri.org/2002/10/soap/reliability/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding"
xmlns:conv="http://www.openuri.org/2002/04/wsdl/conversation/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://www.inlandrevenue.gov.uk/schemas/AntiVirusSoapService">
<message name="scanForViruses">
<part xmlns artns="http://www.w3.org/2001/XMLSchema"
type="partns:anyType"
name="dataHandler">
</part>
</message>
<message name="scanForVirusesResponse">
<part xmlns artns="http://www.w3.org/2001/XMLSchema"
type="partns:string"
name="result">
</part>
</message>
<portType name="AntiVirusProcessPort">
<operation name="scanForViruses">
<input message="tns:scanForViruses">
</input>
<output message="tns:scanForVirusesResponse">
</output>
</operation>
</portType>
<binding type="tns:AntiVirusProcessPort"
name="AntiVirusProcessPort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http">
</soap:binding>
<operation name="scanForViruses">
<soap peration style="rpc"
soapAction="">
</soap peration>
<input>
<soap:body namespace="http://www.inlandrevenue.gov.uk/schemas/AntiVirusSoapService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded">
</soap:body>
</input>
<output>
<soap:body namespace="http://www.inlandrevenue.gov.uk/schemas/AntiVirusSoapService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded">
</soap:body>
</output>
</operation>
</binding>
<service name="AntiVirusProcess">
<port name="AntiVirusProcessPort"
binding="tns:AntiVirusProcessPort">
<soap:address location="http://localhost:11001/AntiVirus/AntiVirusProcess">
</soap:address>
</port>
</service>
</definitions>
------ localhost:3669->10.101.193.171:11001 ------
POST /AntiVirus/AntiVirusProcess HTTP/1.0
Content-Type: multipart/related;type="text/xml";boundary="----=_Part_3_2425209.1149760420359";start=__WLS__1149760420359__SOAP__; charset=utf-8
SOAPAction: ""
User-Agent: Java1.4.2_08
Host: localhost:11001
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: Keep-Alive
Content-Length: 94199


------ localhost:3669->10.101.193.171:11001 ------

------=_Part_3_2425209.1149760420359
Content-Type: text/xml; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-ID: __WLS__1149760420359__SOAP__

<?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
------=_Part_3_2425209.1149760420359
Content-Id: <dataHandler>


Hello World
JUVPRgo=
[09090909]
------=_Part_3_2425209.1149760420359--

------ 10.101.193.171:11001->localhost:3669 ------
HTTP/1.1 200 OK
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help in passing a string as a attachment
 
Similar Threads
Errors when using clientgen
What's wrong with my wsdl?
error while connecting to webservices
BP Analyzer
Soap & attachments: encoded or literal??