Serious WCF problem

COBRASoft

Active Member
Licensed User
Longtime User
Hi,

I have a serious WCF problem. If you go to the following link in your browser, you'll get a JSon result.

http://cobra-soft.no-ip.info:2080/Q2CService2.svc/GetAfdelingen?Login=cobrasoft&password=cobrasoft

I can't get this info from B4A with HTTPUtils. Can somebody please help me? This is *VERY* urgent :sign0013:.

Greetings,
Sigurd


WCF Service definition for this URL on my Server:
<OperationContract()>
<WebInvoke(method:="GET")>
Public Function GetRBCountPerDay(ByVal Login As String, ByVal Password As String, ByVal AfdelingCONT_ID As String, ByVal DateFrom As Date, ByVal DateTill As Date) As List(Of RBCountPerDay)
Dim CurrentCONT_ID = CheckUser(Login, Password)
If Not CurrentCONT_ID.HasValue OrElse CurrentCONT_ID.Value = Guid.Empty Then
Return Nothing
Else
Dim objAfdelingCONT_ID = New Guid(AfdelingCONT_ID)
DateTill = DateTill.Date.AddDays(1)
Using ctxQ2C As New Q2CModel.Q2CEntities
Dim varResult = From d In ctxQ2C.Document
Where d.DCMT_Type = 14 AndAlso d.DCMT_DatumUitvoer.HasValue AndAlso
d.DCMT_Locatie_ID.HasValue AndAlso d.DCMT_Locatie_ID = objAfdelingCONT_ID AndAlso
d.DCMT_DatumUitvoer.Value >= DateFrom AndAlso d.DCMT_DatumUitvoer.Value < DateTill
Group By Base = New With {d.DCMT_Locatie_ID, d.DCMT_DatumUitvoer.Value.Year,
d.DCMT_DatumUitvoer.Value.Month, d.DCMT_DatumUitvoer.Value.Day} Into Aantal = Group
Order By Base.DCMT_Locatie_ID, Base.Year, Base.Month, Base.Day
Select New RBCountPerDay With {.DCMT_Locatie_ID = Base.DCMT_Locatie_ID, .Year = Base.Year, .Month = Base.Month, .Day = Base.Day, .Count = Aantal.Count()}

Return varResult.ToList
End Using
End If
End Function
 

evilpaw

Member
Licensed User
Longtime User
Simple App

Here is an example that i got going. I created a simple layout with 2 buttons.
Load button
Parse Button

It calls the methods respectively.

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

   Dim URL As String
    URL = "http://cobra-soft.no-ip.info:2080/Q2CService2.svc/GetAfdelingen?Login=cobrasoft&password=cobrasoft"
   Dim HttpClient1 As HttpClient
   'Dim sJSONData   As String 
   
End Sub

Sub Globals
   Dim sJSONData   As String
   Dim Load As Button
   Dim Parse As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   HttpClient1.Initialize("HttpClient1")
   Activity.LoadLayout("json1") 'Load the layout file.
End Sub

Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   Log("ResponseSuccess")
   ProgressDialogHide
   Dim result As String
   result = Response.GetString("UTF8") 'Convert the response to a string
   sJSONData = result
   Log(result) ' test dump
End Sub

Sub HttpClient1_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
   Log(Reason)
   Log(StatusCode)
   ProgressDialogHide
   msg = "Error connecting to server."
   If reason <> Null Then msg = msg & CRLF & Reason
   ToastMessageShow (msg, True)
End Sub

Sub GetJSONData()
    Dim request As HttpRequest
   request.InitializeGet(URL)
   request.Timeout = 10000 'set timeout to 10 seconds
   If HttpClient1.Execute(request, 1) = False Then Return 'Will be false if their is already a running task (with the same id).
   ProgressDialogShow("Calling server...")

End Sub

Sub LoadJSONDATA()
   Dim JSON As JSONParser
   Dim Map1 As Map
   Dim i As Int 
   
   JSON.Initialize(sJSONData)
   Map1.Initialize
   
   Dim m As Map 'helper map for navigating
   Dim DataItems As List
   DataItems.Initialize2(JSON.NextArray )
   
   m.Initialize
   
   Log(DataItems.Size)
   
   For i = 0 To DataItems.Size-1
      m = DataItems.Get(i)
      Log (m.Get("CONT_ID"))
      Log (m.Get("CONT_Kenmerk"))
      
      
   Next
   

End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Parse_Click
   LoadJSONDATA
End Sub
Sub Load_Click
    GetJSONData
End Sub
 
Last edited:
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
Hi,

Thanks for the samples. You use the download function, never thought of that!

I have a lot of problems with 'POST' with WCF services. With ASP.Net services this worked fine. I guess I have to do a lot more research on my webservice part. When that's working, I'll continue searching for the 'POST'.

Greetings,
Sigurd
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
HTTPUtlis is missing contenttype

Hi,

I searched for hours to get POST working with WCF services in JSon format. :BangHead:

With HTTPClient it was quite straightforward once I figured out how to provide the message for POST and use the correct web.config in WCF.

With HTTPUtils this is not possible unless you make an important change in both HTTPUtils and HTTPUtilsService (both included in zip). HTTPUtils doesn't set the ContentType in the HTTPRequest. For JSon and WCF this is required or it WON'T WORK!

Erel, perhaps you can modify your module and service in the specific thread for HTTPUtils so other people won't have to search for this solution.

Greetings,
Sigurd
 

Attachments

  • HttpUtils.zip
    2.5 KB · Views: 364
Upvote 0

hdtvirl

Active Member
Licensed User
Longtime User
WCF Service and config files.

CobraSoft, what did you have to add to the web.config file to get this working.

Writing the service is the easy part, configuring the WEB.CONFIG file is a Pain in the Rear End. !!!

Thanks in advance

BOB.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…