Using Android ksoap2, I'm trying to communicate with an example .NET web service. I keep getting http response code 415. I've tried many things, many from this site and would be grateful for any ideas..
Service.cs:
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
IService.cs:
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
Android:
try
{
SoapPrimitive response;
SoapObject request = new SoapObject("http://tempuri.org/", "GetData");
request.addProperty("value", 0);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://www.testsite.com/servicetest/Service.svc");
androidHttpTransport.call("http://tempuri.org/GetData", envelope);
response=(SoapPrimitive)envelope.getResponse();
}
catch(Exception e)
{
Log.e("Exception:",e.getMessage());
}
The exception always occurs on the androidHttpTransport.call line with 'HTTP request failed, HTTP status:415. Debugging the web service, I can see it works on localhost and http://www.testsite.com/servicetest/, but not when called from the Android app. Any ideas?