I am trying to use a Web Service in Matlab but I have a problem.
The webservice sends a cookie for authentication which matlab ignores.
The matlab function callSoapService uses this java code:
url = URL(endpoint);
if isempty(proxy)
httpConn = url.openConnection;
else
httpConn = url.openConnection(proxy);
end
httpConn.setRequestProperty('Content-Type','text/xml; charset=utf-8');
httpConn.setRequestProperty('SOAPAction',soapAction);
httpConn.setRequestMethod('POST');
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
outputStream = httpConn.getOutputStream;
outputStream.write(b);
outputStream.close;
inputStream = httpConn.getInputStream;
byteArrayOutputStream = java.io.ByteArrayOutputStream;
isc = InterruptibleStreamCopier.getInterruptibleStreamCopier;
isc.copyStream(inputStream,byteArrayOutputStream);
inputStream.close;
byteArrayOutputStream.close;
resp = byteArrayOutputStream.toString('UTF-8');
If I write httpConn.getHeaderFields() it returns an empty list, instead of the headers with the cookie. Any idea?
In the java documentation it says you should call httpConn.connect() and Matlab does not do that, I added that line somewhere in the code just to try, but it didnt work lol
I found the solution.
ASP.NET was not sending the cookie because the browser capabilities object for the java user agent Mozilla/5.0 (Java 1.6.0_17; Windows 7 6.1 amd64; en_US) ICEbrowser/v6_0_2 returns false in the Cookies field.
I created a new java.browser file and put it in the App_Browsers directory. I redeployed the application and it worked! ASP.Net sends the cookie to Matlab.
What I had to do next is to modify the Matlab Soap function so it would receive and resend the cookie everytime. I posted the solution to that in http://www.cadec-online.com/Help/API.aspx#Matlab
I reported this issue to matlab: http://www.mathworks.com/support/service_requests/Service_Request_Detail.do?row_id=1-GQMEDO
http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilities.aspx