Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am calling AJAX enabled WCF Service from android using HttpPost. I am passing JSONObject as data. The JSONObject is in the following format,

{"Enq":
{
"Enquiry":
{
"EnquiryDate":"2013-9-30",
"Remarks":"Mke it soon.",
"Location":"Chennai",
"Id":1,
"RequiredDate":"2013-10-30"
},
"EnquiryDetails":
[
{"SaleCondition":"IIWL","EnquiryId":1,"Type":"GP","NoOfUnits":54,"Size":"4"}{"SaleCondition":"ASIS","EnquiryId":1,"Type":"GP","NoOfUnits":23,"Size":"40"}, {"SaleCondition":"IIWL","EnquiryId":1,"Type":"GP","NoOfUnits":34,"Size":"40"}
]
}
}

I use the following code to call the Wcf Service,

DefaultHttpClient httpClient = new DefaultHttpClient();
URI uri = null;
uri = new URI("http://10.1.193.172/iTradeIntegration/MobileApp.svc");
HttpPost httppost=new HttpPost(uri +"/enquirySync");
StringEntity se = new StringEntity( parent.toString());

//parent is JSONObject which is in the above format

se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json; charset=utf-8");
HttpResponse response = null;
response = httpClient.execute(httppost);

And in the WCF Service, i defined the function to consume the HttpPost as follow,

<operationcontract()> _
<webinvoke(method:> _
Public Function enquirySync(Enq As List(Of JsonObject)) As String
Return "Hi"
End Function
End Class

I defined the classes to consume the values. Those are given below.

Public Class Enquiry
Public Property EnquiryDate() As String
Get
Return m_EnquiryDate
End Get
Set(value As String)
m_EnquiryDate = Value
End Set
End Property
Private m_EnquiryDate As String

Public Property Remarks() As String
Get
Return m_Remarks
End Get
Set(value As String)
m_Remarks = Value
End Set
End Property
Private m_Remarks As String

Public Property Location() As String
Get
Return m_Location
End Get
Set(value As String)
m_Location = Value
End Set
End Property
Private m_Location As String

Public Property Id() As Integer
Get
Return m_Id
End Get
Set(value As Integer)
m_Id = Value
End Set
End Property
Private m_Id As Integer

Public Property RequiredDate() As String
Get
Return m_RequiredDate
End Get
Set(value As String)
m_RequiredDate = Value
End Set
End Property
Private m_RequiredDate As String
End Class




Public Class EnquiryDetail
Public Property SaleCondition() As String
Get
Return m_SaleCondition
End Get
Set(value As String)
m_SaleCondition = Value
End Set
End Property
Private m_SaleCondition As String

Public Property EnquiryId() As Integer
Get
Return m_EnquiryId
End Get
Set(value As Integer)
m_EnquiryId = Value
End Set
End Property
Private m_EnquiryId As Integer

Public Property Type() As String
Get
Return m_Type
End Get
Set(value As String)
m_Type = Value
End Set
End Property
Private m_Type As String

Public Property NoOfUnits() As Integer
Get
Return m_NoOfUnits
End Get
Set(value As Integer)
m_NoOfUnits = Value
End Set
End Property
Private m_NoOfUnits As Integer

Public Property Size() As String
Get
Return m_Size
End Get
Set(value As String)
m_Size = Value
End Set
End Property
Private m_Size As String
End Class



Public Class Enq
Public Property Enquiry() As Enquiry
Get
Return m_Enquiry
End Get
Set(value As Enquiry)
m_Enquiry = Value
End Set
End Property
Private m_Enquiry As Enquiry

Public Property EnquiryDetails() As List(Of EnquiryDetail)
Get
Return m_EnquiryDetails
End Get
Set(value As List(Of EnquiryDetail))
m_EnquiryDetails = Value
End Set
End Property
Private m_EnquiryDetails As List(Of EnquiryDetail)
End Class



Public Class JsonObject
Public Property Enq() As Enq
Get
Return m_Enq
End Get
Set(value As Enq)
m_Enq = Value
End Set
End Property
Private m_Enq As Enq
End Class


I am not getting the values which i have passed from android. Please help me to solve this. I am getting "nothing" for the values.
Posted
Updated 1-Oct-13 3:45am
v4

1 solution

Check the discussion and solution of:
Android app won't return result from VB.NET WCF Service[^]
And also the tutorial:
WCF and Android: Part II[^]
 
Share this answer
 
Comments
Annamalai09 2-Oct-13 0:25am    
Ridoy, i dont want vb.net to send any value to android app. i just want to send a jsonobject from android app to WCF service.
ridoy 2-Oct-13 13:27pm    
Ok,then check http://stackoverflow.com/questions/8281985/passing-json-object-from-android-client-to-wcf-restful-service-in-c-sharp, http://stackoverflow.com/questions/16550117/android-post-a-json-object-to-wcf-receiving-null.
Annamalai09 2-Oct-13 13:41pm    
Ridoy, Thanks for your help and efforts. I myself found the solution for my requirement. For the JsonObject format which i am passing from android, i have to create two parameters in vb.net function. this is the solution for my question..
ridoy 2-Oct-13 13:44pm    
Well,you can share it here if you want which will help others also in future.
Annamalai09 2-Oct-13 13:57pm    
ya sure.. will do..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900