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

Windows Forms Discussion :

[C#] Accéder à un service web via SOAP


Sujet :

Windows Forms

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Points : 314
    Points
    314
    Par défaut [C#] Accéder à un service web via SOAP
    Bonjour à tous,
    Voilà mon problème.

    J'ai réalisé un petit service web (en perl) et je voudrais pouvoir y accéder depuis une form developpée en C#.

    J'arrive à faire fonctionner mon service web lorsque le client est développé en perl. Mais alors en C#, je suis perdu ... je ne sais pas comment faire.

    Je poste ici le code su service développé en perl u cas où ça puisse aider pour me mettre sur la piste (car je ne crois pas être très clair):

    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
     
    use SOAP::Transport::HTTP;
      SOAP::Transport::HTTP::CGI      
        -> dispatch_to('Login')        
        -> handle;
      package Login;
      use SF::BD;
     
      sub CheckLoginAccount()
      {
            my ($user,$pass)=@_;
            my $dbh=&SF::BD::Connexion();
            $code=&SF::BD::CheckLogin($dbh,$user,$pass);
            &SF::Deconnexion($dbh);
            return $code;
      }
    1;
    Comment à accéder en C# à ce service ???

    Merci pour votre aide !!! et bon week end !!
    tout le monde est d'accord pour critiquer la pensée unique

  2. #2
    Membre à l'essai

    Profil pro
    Inscrit en
    Mai 2006
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Mai 2006
    Messages : 20
    Points : 19
    Points
    19
    Par défaut
    Salut,

    pour cela il te faut générer un WSDL.
    Il doit y avoir un outil qui te génère cela à partir de ton script PERL.
    Puis tu utilises le programme WSDL.exe (qui est fourni avec Visual Studio) pour générer ta classe csharp (ton proxy) à partir de ton WSDL qui te fournira automatiquement un accés à tes méthodes exposées par ton Web Service :

    wsdl /o:tac_lasse_CSharp_à_créer.cs ton_WSDL.wsdl

    Rodolphe

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Points : 314
    Points
    314
    Par défaut
    Bonjour Rodolphe et merci pour ta réponse !!

    Je ne suis pas sûr d'avoir tout compris. Je vais dans un premier temps tenter de créer la classe proxy avec wsdl.exe (est-ce bien cela ?)
    tout le monde est d'accord pour critiquer la pensée unique

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Points : 314
    Points
    314
    Par défaut
    Alors j'ai créé le wsdl qui donne la description des méthodes fournit par le service web écrit en perl.

    J'ai utilisé l'outil wsdl.exe pour généré la classe proxy.
    Je l'ai ajouté à mon projet en faisant ajouter->élément existant
    et j'ai ajouté: myProxyClass.cs

    Elle ressemble à cela:
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    //------------------------------------------------------------------------------
    // <auto-generated>
    // Ce code a ‚t‚ g‚n‚r‚ par un outil.
    // Version du runtime :2.0.50727.42
    //
    // Les modifications apport‚es … ce fichier peuvent provoquer un comportement incorrect et seront perdues si
    // le code est r‚g‚n‚r‚.
    // </auto-generated>
    //------------------------------------------------------------------------------
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;
    // 
    // Ce code source a ‚t‚ automatiquement g‚n‚r‚ par wsdl, Version=2.0.50727.42.
    // 
     
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="TESTTESTBinding", Namespace="http://127.0.0.1/v2")]
    publicpartialclassTEST : System.Web.Services.Protocols.SoapHttpClientProtocol {
    
    private System.Threading.SendOrPostCallback TEST_ITOperationCompleted;
    
    ///<remarks/>
    public TEST() {
    this.Url = "http://127.0.0.1/v2";
    }
    
    ///<remarks/>
    publiceventTEST_ITCompletedEventHandler TEST_ITCompleted;
    
    ///<remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: System.Xml.Serialization.XmlElementAttribute("TEST_ITResponse", Namespace="http://127.0.0.1/soap_test.xsd")]
    publicstring TEST_IT([System.Xml.Serialization.XmlElementAttribute(Namespace="http://127.0.0.1/soap_test.xsd")] string TEST_ITRequest) {
    object[] results = this.Invoke("TEST_IT", newobject[] {
    TEST_ITRequest});
    return ((string)(results[0]));
    }
    
    ///<remarks/>
    public System.IAsyncResult BeginTEST_IT(string TEST_ITRequest, System.AsyncCallback callback, object asyncState) {
    returnthis.BeginInvoke("TEST_IT", newobject[] {
    TEST_ITRequest}, callback, asyncState);
    }
    
    ///<remarks/>
    publicstring EndTEST_IT(System.IAsyncResult asyncResult) {
    object[] results = this.EndInvoke(asyncResult);
    return ((string)(results[0]));
    }
    
    ///<remarks/>
    publicvoid TEST_ITAsync(string TEST_ITRequest) {
    this.TEST_ITAsync(TEST_ITRequest, null);
    }
    
    ///<remarks/>
    publicvoid TEST_ITAsync(string TEST_ITRequest, object userState) {
    if ((this.TEST_ITOperationCompleted == null)) {
    this.TEST_ITOperationCompleted = new System.Threading.SendOrPostCallback(this.OnTEST_ITOperationCompleted);
    }
    this.InvokeAsync("TEST_IT", newobject[] {
    TEST_ITRequest}, this.TEST_ITOperationCompleted, userState);
    }
    
    privatevoid OnTEST_ITOperationCompleted(object arg) {
    if ((this.TEST_ITCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.TEST_ITCompleted(this, newTEST_ITCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    }
    }
    
    ///<remarks/>
    publicnewvoid CancelAsync(object userState) {
    base.CancelAsync(userState);
    }
    }
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    publicdelegatevoidTEST_ITCompletedEventHandler(object sender, TEST_ITCompletedEventArgs e);
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    publicpartialclassTEST_ITCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    
    privateobject[] results;
    
    internal TEST_ITCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
    base(exception, cancelled, userState) {
    this.results = results;
    }
    
    ///<remarks/>
    publicstring Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((string)(this.results[0]));
    }
    }
    }
    
    Mais lors de la génération du projet, j'ai l'erreur suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Erreur 1 Le type ou le nom d'espace de noms 'Services' n'existe pas dans la classe ou l'espace de noms 'System.Web' (une référence d'assembly est-elle manquante ?) C:\Documents and Settings\$fgle.ZA\Mes documents\Visual Studio 2005\Projects\PicsWizz\PicsWizz\myProxyClass.cs 14 18 PicsWizz
    Qu'est ce que cela veut dire ?? il n'arrive pas à charger la "bibliothèque" system.Web.Services ?? l'intellisense ne me montre pas cette "bibliothèque" ??
    Que faire ???
    tout le monde est d'accord pour critiquer la pensée unique

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Points : 314
    Points
    314
    Par défaut
    Pardon, j'ai trouvé la cause de cette erreur sur google.
    Je n'avais pas ajouté la référence.

    Dans l'arborescence du projet: clik droit sur référence puis ajouter une référence. Dans l'onglet .NET sélectionner System.Web.Services

    La compilation a réussi !! Mais !!! j'ai une erreur lors de l'éxécution.

    L'erreur est la suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>301 Moved Permanently</TITLE>
    </HEAD><BODY>
    <H1>Moved Permanently</H1>
    The document has moved <A HREF="<A href="http://127.0.0.1/v2/">here</A>.<P">http://127.0.0.1/v2/">here</A>.<P>
    <HR>
    <ADDRESS>Apache/1.3.33 Server at <A HREF="<A href="mailto:admin@localhost">127.0.0.1</A">mailto:admin@localhost">127.0.0.1</A> Port 80</ADDRESS>
    </BODY></HTML>
    Je ne comprends pas ce que ça veut dire ....
    J'ai regardé dans la log d'erreur apache: rien ... pas une ligne d'erreur.
    Quelqu'un peut il m'aider la dessus ??

    Merci grandement !!
    tout le monde est d'accord pour critiquer la pensée unique

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    801
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 801
    Points : 314
    Points
    314
    Par défaut
    Je pense avoir corrigé cette erreur mais une nouvelle apparait !!!

    A tout hasardj je poste ici le wsdl généré
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    //------------------------------------------------------------------------------
    // <auto-generated>
    // Ce code a ‚t‚ g‚n‚r‚ par un outil.
    // Version du runtime :2.0.50727.42
    //
    // Les modifications apport‚es … ce fichier peuvent provoquer un comportement incorrect et seront perdues si
    // le code est r‚g‚n‚r‚.
    // </auto-generated>
    //------------------------------------------------------------------------------
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;
    // 
    // Ce code source a ‚t‚ automatiquement g‚n‚r‚ par wsdl, Version=2.0.50727.42.
    // 
     
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="TEST_FunctionsTEST_FunctionsBinding", Namespace="http://161.120.218.23/TEST/")]
    publicpartialclassTEST_Functions : System.Web.Services.Protocols.SoapHttpClientProtocol {
    
    private System.Threading.SendOrPostCallback HelloWorldOperationCompleted;
    
    ///<remarks/>
    public TEST_Functions() {
    this.Url = "http://161.120.218.23/cgi-bin/TEST.pm";
    }
    
    ///<remarks/>
    publiceventHelloWorldCompletedEventHandler HelloWorldCompleted;
    
    ///<remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: System.Xml.Serialization.XmlElementAttribute("HelloWorldResponse", Namespace="http://161.120.218.23/TEST.wsdl")]
    publicstring HelloWorld([System.Xml.Serialization.XmlElementAttribute(Namespace="http://161.120.218.23/TEST.wsdl")] string HelloWorldRequest) {
    object[] results = this.Invoke("HelloWorld", newobject[] {
    HelloWorldRequest});
    return ((string)(results[0]));
    }
    
    ///<remarks/>
    public System.IAsyncResult BeginHelloWorld(string HelloWorldRequest, System.AsyncCallback callback, object asyncState) {
    returnthis.BeginInvoke("HelloWorld", newobject[] {
    HelloWorldRequest}, callback, asyncState);
    }
    
    ///<remarks/>
    publicstring EndHelloWorld(System.IAsyncResult asyncResult) {
    object[] results = this.EndInvoke(asyncResult);
    return ((string)(results[0]));
    }
    
    ///<remarks/>
    publicvoid HelloWorldAsync(string HelloWorldRequest) {
    this.HelloWorldAsync(HelloWorldRequest, null);
    }
    
    ///<remarks/>
    publicvoid HelloWorldAsync(string HelloWorldRequest, object userState) {
    if ((this.HelloWorldOperationCompleted == null)) {
    this.HelloWorldOperationCompleted = new System.Threading.SendOrPostCallback(this.OnHelloWorldOperationCompleted);
    }
    this.InvokeAsync("HelloWorld", newobject[] {
    HelloWorldRequest}, this.HelloWorldOperationCompleted, userState);
    }
    
    privatevoid OnHelloWorldOperationCompleted(object arg) {
    if ((this.HelloWorldCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.HelloWorldCompleted(this, newHelloWorldCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    }
    }
    
    ///<remarks/>
    publicnewvoid CancelAsync(object userState) {
    base.CancelAsync(userState);
    }
    }
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    publicdelegatevoidHelloWorldCompletedEventHandler(object sender, HelloWorldCompletedEventArgs e);
    ///<remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    publicpartialclassHelloWorldCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    
    privateobject[] results;
    
    internal HelloWorldCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
    base(exception, cancelled, userState) {
    this.results = results;
    }
    
    ///<remarks/>
    publicstring Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((string)(this.results[0]));
    }
    }
    }
    
    J'appelle une instance de la classe TEST_Functions ainsi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    TEST_Functions T = newTEST_Functions();
    T.HelloWorld("");
    
    Pas de problème jusqu'à l'appel de la méthode HelloWorld();

    A ce moment, j'ai l'erreur suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    La demande a échoué avec l'état HTTP 405 : Method Not Allowed.
    et la fin du détail d'execption est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    L'exception System.Net.WebException n'a pas été gérée
      Message="La demande a échoué avec l'état HTTP 405 : Method Not Allowed."
      Source="System.Web.Services"
      StackTrace:
           à System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
           à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
           à TEST_Functions.HelloWorld(String HelloWorldRequest) dans C:\Documents and Settings\$fgle.ZA\Mes documents\Visual Studio 2005\Projects\PicsWizz\PicsWizz\myProxyClass.cs:ligne 44
           à PicsWizz.propriétés.WebServiceFunctions(Object sender, EventArgs e) dans C:\Documents and Settings\$fgle.ZA\Mes documents\Visual Studio 2005\Projects\PicsWizz\PicsWizz\propriétés.cs:ligne 32
           à System.Windows.Forms.Control.OnClick(EventArgs e)
           à System.Windows.Forms.Button.OnClick(EventArgs e)
    Si quelq'un a une idée, je suis preneur !!!!

    Bonne soirée !!!
    tout le monde est d'accord pour critiquer la pensée unique

Discussions similaires

  1. Accéder aux services Web via Android
    Par Feanorin dans le forum API standards et tierces
    Réponses: 8
    Dernier message: 08/06/2015, 16h04
  2. comment accéder à un service web wsdl via JavaScript
    Par berber5 dans le forum Services Web
    Réponses: 2
    Dernier message: 13/06/2012, 15h05
  3. Appel service Web avec SOAP:Lite
    Par phlux dans le forum Web
    Réponses: 1
    Dernier message: 09/04/2008, 16h56
  4. VBA : Service Web avec SOAP et HTTPS
    Par uftu1 dans le forum VBA Access
    Réponses: 1
    Dernier message: 06/09/2007, 12h02

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