Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SAAJ Client with attachment accessing .Net Web Service

843833Jun 1 2005 — edited Aug 24 2005
Hi,

I'm using the SAAJ API to send a message with an attachment to a .Net web service. I followed the example in the J2EE tutorial and my code manages to call the web service correctly when I don't include an attachment, however when I include an attachment it returns the following error:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"><wsu:Created>2005-06-01T19:43:39Z</wsu:Created><wsu:Expires>2005-06-01T19:48:39Z</wsu:Expires></wsu:Timestamp></soap:Header><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapHeaderException: The message is not a valid XML message ---> System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at Microsoft.Web.Services.XmlSkipDTDReader.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Microsoft.Web.Services.SoapEnvelope.Load(Stream stream)
...


Here is the code:

// Prepare the message
			MessageFactory factory = MessageFactory.newInstance();
			SOAPMessage message = factory.createMessage();
			
			MimeHeaders hd = message.getMimeHeaders();
			hd.addHeader("SOAPAction", "http://tempuri.org/EchoString");
			
			SOAPPart soapPart = message.getSOAPPart();
			SOAPEnvelope env = soapPart.getEnvelope();

SOAPBody body = message.getSOAPBody();
			SOAPFactory soapFactory = SOAPFactory.newInstance();
			Name bodyName = soapFactory.createName( "EchoString", "", "http://tempuri.org/" );
			SOAPBodyElement bodyElement = body.addBodyElement( bodyName );
			Name name = soapFactory.createName("param");
			SOAPElement param = bodyElement.addChildElement( name );
			param.addTextNode( "ParamValue");

AttachmentPart ap1 = message.createAttachmentPart("Attachment", "text/plain");
			message.addAttachmentPart( ap1 );

// Send the message
			SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
			SOAPConnection soapConnection = soapConnectionFactory.createConnection();
			
			URL endPoint = new URL( "http://localhost/WSEcho/Echo.asmx" );
			SOAPMessage response = soapConnection.call( message, endPoint );
Anybody seen this error?

Thanks in advance.

Craig
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2005
Added on Jun 1 2005
4 comments
216 views