IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Discussion :

WCF Web Service avec JSON Format


Sujet :

Services Web

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2013
    Messages : 9
    Points : 5
    Points
    5
    Par défaut WCF Web Service avec JSON Format
    J'ai crées un WCF avec format de retour JSON Le probleme que je peux pas appeler mon service a partir du client android et quand je mets un autre lien au niveau du code android ça fonctionne ce qui implique que le problème est dans le code C# pouvez vous m'aider

    Code de mon service
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    namespace WcfService1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface IService1
        {
     
            [OperationContract]
            [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
                                       BodyStyle = WebMessageBodyStyle.Bare,
                                       UriTemplate = "GetData.txt")]
            string GetData();
     
            [OperationContract]
            [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
                                      BodyStyle = WebMessageBodyStyle.Wrapped,
                                      UriTemplate = "GetDataUsingDataContract/")]
            List<CompositeType> GetDataUsingDataContract();
     
            // TODO: Add your service operations here
        }
     
     
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
     
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
     
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }
    }
    Mon Fichier de configuration
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WcfService1.Service1Behavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
     
          <endpointBehaviors>
            <behavior name="tbl">
              <webHttp defaultOutgoingResponseFormat="Json"/>
            </behavior>
          </endpointBehaviors>
     
        </behaviors>
        <services>
          <service behaviorConfiguration="WcfService1.Service1Behavior" name="WcfService1.Service1">
            <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1"  behaviorConfiguration="tbl">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:52570/Service1" />
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
    mon code android

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    package com.example.algorismi.myapplication;
     
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.widget.TextView;
    import android.widget.Toast;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
     
    @SuppressWarnings("ALL")
    public class MainActivity extends AppCompatActivity {
     
     
        public final String feelURL = "http://192.168.1.5:52570/Service1.svc/GetData.txt";
       // public final String feelURL = "http://jsonparsing.parseapp.com/jsonData/moviesDemoItem.txt"; // Lien fonctionne
     
        String responseString;
        TextView txtView;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            MyAsyncTask mytask = new MyAsyncTask();
            mytask.execute("Sending parameter","Second param");
        }
     
        private class MyAsyncTask extends AsyncTask<String, Void, String>{
     
            public StringBuffer buffer;
     
            @Override
            protected String doInBackground(String... params) {
                String myFirstParam = params[0];
               // StringBuffer buffer;
                BufferedReader reader = null;
                HttpURLConnection client = null;
                try {
                    URL url = new URL(feelURL);
                    client = (HttpURLConnection) url.openConnection();
                    client.connect();
                    Log.i("Connexion", "Connexion est etablie avec succée");
     
                    buffer = new StringBuffer();
                    InputStream is = client.getInputStream();
                    reader = new BufferedReader(new InputStreamReader(is));
                    String line="";
                    while ((line = reader.readLine()) != null)
                    {
                        buffer.append(line);
                    }
                    Log.i("Connexion", buffer.toString());
     
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if(client != null)
                    client.disconnect();
                    try {
                        if(reader != null)
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                Log.i("Algorismi", "Terminée");
                return myFirstParam;
            }
     
            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                Toast.makeText(MainActivity.this,s,Toast.LENGTH_SHORT).show();
                TextView txt = (TextView)findViewById(R.id.txtResult);
                txt.setText(buffer.toString());
            }
        }
    }

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    612
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 612
    Points : 338
    Points
    338
    Par défaut
    Bonjour,

    Ton projet est en Soap ou en REST?

    Tu arrive a visualiser ton contrat depuis un simple browser? (depuis ton PC de dev)

    As-tu essayé de l'attaquer avec un client de test?

    Soap => SoapUI
    REST => Advanced Rest Client (extension chrome)

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2013
    Messages : 9
    Points : 5
    Points
    5
    Par défaut
    Mon Service est REST
    et je ne connais pas "Advanced Rest Client" pouvez vous me faire comprendre.

Discussions similaires

  1. Appeler un web service avec pl/sql
    Par squalito dans le forum PL/SQL
    Réponses: 5
    Dernier message: 17/09/2012, 16h21
  2. [Debutant]création de web services avec JWS
    Par Mehdi_82 dans le forum Services Web
    Réponses: 3
    Dernier message: 09/07/2008, 21h22
  3. [Debutant] Web services avec Jboss WS
    Par nesbla dans le forum Services Web
    Réponses: 1
    Dernier message: 14/08/2006, 14h52
  4. Déploiement de Web Service avec InstallShield
    Par _beber85 dans le forum Services Web
    Réponses: 7
    Dernier message: 12/07/2006, 14h28
  5. [Web Service][avec Struts]un tuto? un lien?
    Par javazer dans le forum Struts 1
    Réponses: 3
    Dernier message: 28/03/2006, 19h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo