来自Android的Wcf服务电话 [英] Wcf Service Call From Android
问题描述
我使用 HttpPost 从Android调用支持AJAX的WCF服务。我将JSONObject作为数据传递。 JSONObject采用以下格式,
{Enq:
{
查询:
{
EnquiryDate:2013-9-30,
备注:很快就会结束。,
位置:Chennai,
Id:1,
RequiredDate:2013-10-30>
},
EnquiryDetails:
[
{SaleCondition:IIWL,EnquiryId:1 , 类型: GP, NoOfUnits:54, 大小: 4} { SaleCondition: ASIS, EnquiryId:1, 类型: GP, NoOfUnits: 23, 大小: 40},{ SaleCondition: IIWL, EnquiryId:1, 类型: GP, NoOfUnits:34, 大小: 40}
]
}
}
我使用以下代码调用Wcf服务,
DefaultHttpClient httpClient = new DefaultHttpClient();
URI uri = null;
uri = new URI(http://10.1.193.172/iTradeInte gration / MobileApp.svc);
HttpPost httppost = new HttpPost(uri +/ enquirySync);
StringEntity se = new StringEntity(parent.toString()) ;
//父是JSONObject,它是上面的格式
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);
在WCF服务中,我定义了消耗HttpPost的函数,如下所示:
< operationcontract()> _
< webinvoke(方法:> _
公共函数enquirySync(Enq As List(Of JsonObject))As String
返回嗨
结束功能
结束班级
我定义了消耗这些值的类。这些是给出的下面。
公共类查询
公共财产EnquiryDate()字符串
获取
返回m_EnquiryDate
结束获取
设置(值为字符串)
m_EnquiryDate = Value
结束集
结束物业
私人m_EnquiryDate为字符串
公共财产备注()为字符串
获取
返回m_Remarks
结束获取
设置(值为字符串)
m_Remarks = Value
结束集
结束物业
私人m_Remarks为S tring
公共财产位置()作为字符串
获取
返回m_Location
结束获取
套装(价值为字符串)
m_Location =价值
结束套件
结束财产
私人m_Location为字符串
公共财产ID()为整数
获取
返回m_Id
结束获取
设置(值为整数)
m_Id =值
结束集>
结束物业
私人m_Id为整数
公共财产RequiredDate()为字符串
获取
返回m_RequiredDate
结束获取
设置(值为字符串)
m_RequiredDate = Value
结束套件
结束财产
私人m_RequiredDate A s String
结束班级
公共类EnquiryDetail
公共财产SaleCondition()为字符串
获取
返回m_SaleCondition
结束获取
设置(值为字符串)
m_SaleCondition =价值
结束集
结束物业
私有m_SaleCondition为字符串
公共财产EnquiryId()为整数
获取
返回m_EnquiryId
结束获取
设置(值为整数)
m_EnquiryId =价值
结束集
结束财产
私人m_EnquiryId为整数
公共财产类型()为字符串
获取
返回m_Type
结束获取
设置(值为字符串)
m_Type =价值
结束集
结束物业
私人m_Type作为字符串
公共属性NoOfUnits()作为整数
获取
返回m_NoOfUnits
结束获取
设置(值为整数)
m_NoOfUnits =价值
结束集
结束物业
私人m_NoOfUnits作为整数
公共财产大小()为字符串
获取
返回m_Size
结束获取
套装(价值为字符串)
m_Size =价值
套装
结束房产
私人m_Size为字符串
结束班级
Public Class Enq
公共财产查询()作为查询
获取
返回m_Enquiry
结束获取
套装(价值作为查询)
m_Enquiry =价值
结束套件
结束财产>
私人m_Enquiry作为查询
公共财产查询详情()列表(EnquiryDetail)
获取
返回m_EnquiryDetails
结束获取
设置(值为列表(EnquiryDetail))
m_EnquiryDetails = Value
结束套票
结束物业
私人m_EnquiryDetails作为清单(EnquiryDetail)
结束班级
公共类JsonObject
公共财产Enq()As Enq
获取
返回m_Enq
结束获取
设置(值为Enq)
m_Enq =价值
结束套票
结束物业
私人m_Enq作为Enq
结束课
我没有得到我从android传递的值。请帮我解决这个问题。我对这些值感到没有。
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.
推荐答案
检查讨论和解决方案:
Android应用程序不会返回VB.NET WCF服务的结果 [ ^ ]
还有教程:
WCF和Android:第二部分 [ ^ ]
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[^]
这篇关于来自Android的Wcf服务电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!