My code is,
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ItemList", mainObject.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.implicitTypes = true;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(SOAP_ACTION, envelope);
} catch (final Exception e) {
activity.runOnUiThread(new Runnable() {
public void run() {
new CustomToast(activity, SOAP_ACTION + " - "
+ e.getMessage() + " error").show();
e.printStackTrace();
}
});
}
try {
fault = (SoapFault) envelope.bodyIn;
activity.runOnUiThread(new Runnable() {
public void run() {
if (fault != null) {
new CustomToast(activity, fault.getMessage())
.show();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
try {
result = (SoapObject) envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
}
whereas mainObject is a JSONObject
, which contain following data,
{"ItemList":[{"ID":"","Name":"Abc","Mark":"81"},{"ID":"","Name":"XYZ","Mark":"82"}]}
I am receiving this in my WCF as following way.
[OperationContract]
void InsertUpdateEntry(Items ItemList);
and Items
class is
[CollectionDataContract(Namespace = "")]
public class Items : List<clsitems>
{
}
and clsitems
class is
[DataContract]
public class clsitems
{
[DataMember]
public string ID { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Mark { get; set; }
}
And finally I am facing following exception.
java.io.IOException: HTTP request failed, HTTP status: 500
I want to send data to Items
class only, so any other solution is also acceptable.
Try setting the ItemName on the CollectionDataContract attribute. For example:
[CollectionDataContract(Name = "Custom{0}List", ItemName = "CustomItem")]
public class Items : List<clsitems>
{
}
The CollectionDataContractAttribute is intended to ease interoperability when working with data from non- providers and to control the exact shape of serialized instances. To this end, the ItemName property enables you to control the names of the repeating items inside a collection. This is especially useful when the provider does not use the XML element type name as the array item name, for example, if a provider uses "String" as an element type name instead of the XSD type name "string".
Taken from here
found solution of your question .. HTTP 500 is an internal server error , so you should check the server is working with SOAPUI or some other tool for starters. Then make sure that you can reach the URL (IP number in this case) from the device and then start debugging the ksaop call.. make sure your webservice is working fine or not
You can enable tracing on the server side like this and check the resulting file including SOAP messages recorded. Then you can identify the problem. Add this to your app.config or web.config. (You may need to change some settings)
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="All">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml" />
</listeners>
</source>
<source name="CardSpace">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.IO.Log">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.Runtime.Serialization">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.IdentityModel">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="xml">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="Traces.svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" traceOutputOptions="ProcessId, ThreadId">
<filter type="" />
</add>
</sharedListeners>
</system.diagnostics>