Hello,
I urgently need some help please. I am trying to find a way to get a session cookie from .NET Web Service. I was told that there is a CookieContainer class which is used to keep .NET Session but it's in C#. Is there a Java equivalent of C# CookieContainer. Is there a way in Java to do the same thing? I've looked at HttpURLConnection "Set-Cookie" in getHeaderField() but I'm not sure if it is able to get a .NET web service's session cookie. I am really new to SOAP and WSDL, this session cookie stuff is making it even harder to make things work.
This is the code I use to send SOAP requests. It's almost exact copy of the code I got from Java's article on SOAP, I just need to get the .NET session cookie somehow. Please help.
//Create the connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
SOAPFactory sf = SOAPFactory.newInstance();
//Create the message
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();
MessageFactory mf2 = MessageFactory.newInstance();
SOAPMessage message2 = mf2.createMessage();
MimeHeaders hd = message.getMimeHeaders();
hd.addHeader("SOAPAction", "http://ws.globaltsg.com/TSGWebServices/Login");
MimeHeaders hd2 = message2.getMimeHeaders();
hd2.addHeader("SOAPAction", "http://ws.globaltsg.com/TSGWebServices/LoadProfile");
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
StreamSource msg = new StreamSource(new FileInputStream("login.xml"));
soapPart.setContent(msg);
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPPart soapPart2 = message2.getSOAPPart();
StreamSource msg2 = new StreamSource(new FileInputStream("loadprof.xml"));
soapPart2.setContent(msg2);
SOAPEnvelope envelope2 = soapPart2.getEnvelope();
SOAPBody body2 = envelope2.getBody();
System.out.println("SOAP Request Sent:");
message.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean( true ));
message.setProperty(Call.SOAPACTION_URI_PROPERTY, "\"http://ws.globaltsg.com/TSGWebServices/WebService.asmx\"");
message2.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean( true ));
message2.setProperty(Call.SOAPACTION_URI_PROPERTY, "\"http://ws.globaltsg.com/TSGWebServices/WebService.asmx\"");
message.writeTo(System.out);
message2.writeTo(System.out);
//Set the destination
URL endpoint = new URL("http://ws.globaltsg.com/TSGWebServices/WebService.asmx");
//Send the messag
SOAPMessage response = connection.call(message, endpoint);
SOAPMessage response2 = connection.call(message2, endpoint);
SOAPBody responseBody = response.getSOAPBody();
SOAPBody responseBody2 = response2.getSOAPBody();
//Close the connection
connection.close();
//Display the response received (Code Sample 3)
System.out.println("SOAP Response Received:");
//Create a transformer
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
//Retrieve content of the response
Source content = response2.getSOAPPart().getContent();
//Display it on the console
StreamResult result = new StreamResult(System.out);
transformer.transform(content, result);
System.out.println();
Thank you,
Victor.
Message was edited by:
vic_sk