I am working on a java client for WCF, and have the template worked out pretty good. I was initially using the web service client project from eclipse but then found out the libraries needed aren’t supported on the android platform. I was then going to use ksoap, but it gave me a lot of issues, so I got a copy of a working soap request
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ITransferService/getInt</Action>
</s:Header>
<s:Body>
<getInt xmlns="http://tempuri.org/">
<i>42</i>
</getInt>
</s:Body>
</s:Envelope>
And decided to make a template that would take in the value and stick it where the 42 goes. When I print it out, it looks like it should work great, but I noticed when I trace that my request is wrapped in CDATA tags.
<MessageLogTraceRecord><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ITransferService/getInt</Action>
</s:Header>
<s:Body>
<getInt xmlns="http://tempuri.org/">
<i>100</i>
</getInt>
</s:Body>
</s:Envelope>
]]></MessageLogTraceRecord>
I am not sure why it is wrapped in CDATA, I am using a HttpURLConnection to make and send the connection. The code that handles that is shown below.
private static void sendRequest(String request) throws Exception
{
URL u = new URL(DEFAULT_SERVER);
URLConnection uc = u.openConnection();
HttpURLConnection connection = (HttpURLConnection)uc;
connection.setRequestProperty("content-type", "text/html; charset=utf8");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("SOAPAction",SOAP_ACTION);
OutputStream out = connection.getOutputStream();
Writer wout = new OutputStreamWriter(out);
wout.write(request);
wout.flush();
wout.close();
System.out.println(connection.getResponseMessage());
}
The request variable is what is shown above, at least what is wrapped in the CDATA tags. When I call System.out.println(connection.getResponseMessage()); then it tells me Unsupported Media Type.
I am using Text as the messageEncoding in my binding configuration for the WCF server
Does anyone have any suggestions as to how I could get my java client to send the data correctly rather than in a cdata wrapper?
Thanks
Nick Long
edit:
I changed this line
connection.setRequestProperty("content-type", "text/html; charset=utf8");
to this
connection.setRequestProperty("content-type", "text/xml");
like it probably should have been to start with. I now get a 500 internal server error, so I’m not sure if I am any closer or not. Any suggestions are still really appreciated
The first change I made was this:
to this
That was what got rid of the 415 error. After that I had the 500 error. What I did to fix that was I took this line
and removed it, making my template this:
The reason, I believe (someone please correct me if I am wrong) that I was getting the 500 error was that I had this line and the line I removed:
After making those changes, my client works great, and I have been able to take it to an image sharing client for the android.