WCF get data

You must Login before you can answer or comment on any questions.

Hi,

I need your help, I have the next code

...
var url = "http://www.........../Service.svc/";
var test = Ti.Network.createHTTPClient({
    onload : function(e) {
        var data = JSON.parse(this.responseText);
        var testArray = [];
        for(var i = 0; i < data.length; i++) {
            var name = {
                title : data[i]
            };
            testArray.push(name);
        }
        table.setData(testArray);
    }
});
test.open("GET", url);
test.send();
...
and the wcf is
IService.cs
[ServiceContract]
public interface IService
{
 
    [OperationContract]
    string GetData(int value);
}
[DataContract]
public class CompositeType
{
    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }
}
 
 
Service.cs
public class Service : IService
{
    public string GetData(int value)
    {
        string value2 = Convert.ToString(value);
        return value2;
    }
}
How do I get data?

Thanks for the answers

— asked 9 months ago by Juan Segura
3 Comments
  • When you post a question like this you really need to provide adequate information. In this case, either post the entire url to the service so someone can see what the request cycle looks like, or at the very least, post the entire output of the response.

    — commented 9 months ago by Anthony Decena

  • sorry

    var url = "http://www.viernesnegro.cr/Service.svc/";

    — commented 9 months ago by Juan Segura

  • [INFO][ActivityManager(   60)] Starting activity: Intent { cmp=com.prueba.Remota/ti.modules.titanium.ui.TiTabActivity (has extras) }
    [INFO][Launcher.Model(  124)] not binding apps: no Launcher activity
    [INFO][TiRootActivity(  264)] (main) [0,0] checkpoint, on root activity resume. activity = com.prueba.Remota.PruebaremotaActivity@43e80e40
    [WARN][ActivityManager(   60)] Activity pause timeout for HistoryRecord{43febf88 com.prueba.Remota/.PruebaremotaActivity}
    [WARN][TiTabActivity(  264)] (main) [407,407] Notifying TiTabGroup, activity is created
    [INFO][ActivityManager(   60)] Displayed activity com.prueba.Remota/ti.modules.titanium.ui.TiTabActivity: 1043 ms (total 4957 ms)
    [INFO][TiAPI   (  264)] <HTML><HEAD><link rel="alternate" type="text/xml" href="http://www.viernesnegro.cr/Service.svc?disco"/><STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}</STYLE><TITLE>Service Service</TITLE></HEAD><BODY><DIV id="content"><P class="heading1">Service Service</P><BR/><P class="intro">You have created a service.<P class='intro'>To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:</P> <BR/><PRE>svcutil.exe <A HREF="http://www.viernesnegro.cr/Service.svc?wsdl">http://www.viernesnegro.cr/Service.svc?wsdl</A></PRE></P><P class="intro"/>This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:<BR/><P class='intro'><B>C#</B></P><PRE><font color="blue">class </font><font color="teal">Test
    [INFO][TiAPI   (  264)] </font>{
    [INFO][TiAPI   (  264)] <font color="blue">    static void </font>Main()
    [INFO][TiAPI   (  264)]     {
    [INFO][TiAPI   (  264)]         <font color="teal">ServiceClient</font> client = <font color="blue">new </font><font color="teal">ServiceClient</font>();
    [INFO][TiAPI   (  264)] 
    [INFO][TiAPI   (  264)] <font color="green">        // Use the 'client' variable to call operations on the service.
    [INFO][TiAPI   (  264)] 
    [INFO][TiAPI   (  264)] </font><font color="green">        // Always close the client.
    [INFO][TiAPI   (  264)] </font>        client.Close();
    [INFO][TiAPI   (  264)]     }
    [INFO][TiAPI   (  264)] }
    [INFO][TiAPI   (  264)] </PRE><BR/><P class='intro'><B>Visual Basic</B></P><PRE><font color="blue">Class </font><font color="teal">Test
    [INFO][TiAPI   (  264)] </font><font color="blue">    Shared Sub </font>Main()
    [INFO][TiAPI   (  264)] <font color="blue">        Dim </font>client As <font color="teal">ServiceClient</font> = <font color="blue">New </font><font color="teal">ServiceClient</font>()
    [INFO][TiAPI   (  264)] <font color="green">        ' Use the 'client' variable to call operations on the service.
    [INFO][TiAPI   (  264)] 
    [INFO][TiAPI   (  264)] </font><font color="green">        ' Always close the client.
    [INFO][TiAPI   (  264)] </font>        client.Close()
    [INFO][TiAPI   (  264)] <font color="blue">    End Sub
    [INFO][TiAPI   (  264)] </font><font color="blue">End Class</font></PRE></DIV></BODY></HTML>
    [ERROR][TiJSError(  264)] (main) [1632,2833] ----- Titanium Javascript Runtime Error -----
    [ERROR][TiJSError(  264)] (main) [0,2833] - In undefined:1,1
    [ERROR][TiJSError(  264)] (main) [1,2834] - Message: Uncaught SyntaxError: Unexpected token <
    [ERROR][TiJSError(  264)] (main) [0,2834] - Source: <HTML><HEAD><link rel="alternate" type="text/xml" href="http://www.viernesnegr
    [ERROR][V8Exception(  264)] Exception occurred at undefined:1: Uncaught SyntaxError: Unexpected token <
    [INFO][ARMAssembler(   60)] generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x35c4f0:0x35c5ac] in 4204882 ns

    — commented 9 months ago by Juan Segura

2 Answers

Your service seems to return an (error) html page. You need to make your reply a json to use it with the code you provided.

I'm sure you've figured this out by now, but you need to call your service like this:

"http://www.viernesnegro.cr/Service.svc/GetData/{value}"

Where {value} is the id of the record you want returned.

Your Answer

Think you can help? Login to answer this question!