J'ai créé les codes suivants pour appeler une sortie de données de service Web et cela a fonctionné. Le problème est quand j'active la clé api sur le logiciel web et que cette clé est générée, pour appeler le service web et avoir besoin de faire un client api pour le demander via un httpRequest, mais mon problème quand je l'exécute dit "La télécommande le serveur a renvoyé une erreur: (404) introuvable. " avez-vous une idée? J'ai tout mon code collé ci-dessous.API Web avec services Web
Merci beaucoup à l'avance
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DisplayDataInformation
{
public partial class DisplayDataInformation : Form
{
public DisplayDataInformation()
{
InitializeComponent();
}
private void Submit(object sender, EventArgs e)
{
localhost.Dashboard proxy = new localhost.Dashboard();
localhost.ProjectMetaData[] pm = proxy.GetAllProjectMetaData();
const string URL = "http://localhost/myProgram/";
const string apiKey = "d26b15b5-e336-48de-9142-939c0e639e8f";
const string Id = "Id";
const string Pass = "pass";
System.Net.HttpWebRequest myHttpWReq;
System.Net.HttpWebResponse myHttpWResp;
//myHttpWReq.ContentLength = 0;
// Make a web request to the web service
myHttpWReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(BLUEURL + "http://localhost/myProgram/Dashboard.asmx" + Id + Pass + apiKey);
myHttpWReq.Method = "Get";
// Get the response of the web service
myHttpWResp = (System.Net.HttpWebResponse)myHttpWReq.GetResponse();
if (myHttpWResp.StatusCode == System.Net.HttpStatusCode.OK)
{
//Create an XML reader to parse the response
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(myHttpWResp.GetResponseStream());
}
//set an string output to the windows form
StringBuilder sb = new StringBuilder();
foreach (localhost.ProjectMetaData value in pm)
{
sb.AppendLine(value.ProjectTitle + " - "
+ value.ProjectID + " - "
+ value.PublishStatus);
// sb.AppendLine("\r\n\t");
}
label1.Text = sb.ToString();
}
}
}
Salut Merci de votre réponse . J'ai fait le changement que vous m'avez donné mais maintenant il me donne une autre erreur Le serveur distant a renvoyé une erreur: (500) Erreur de serveur interne. – user3790916
Salut encore!, Je pourrais enfin effacer le message d'erreur en faisant cela myHttpWReq = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (String.Format ("http: //localhost/BlueWebService55/Dashboard.asmx? Id = {0} & pass = {1} & apiKey = {2} ", BlueId, BluePass, apiKey) + GetAllProjectMetaData); J'ai créé une variable appelée chaîne GetAllProjectMetaData = "", mais le problème est n'affiche rien quand j'appelle le service Web, il semble que la méthode n'est pas consommée par mon client. Dans l'application web, une option permet d'appeler le GetAllProjectMetaData méthode mais de mon application son doesnt doit – user3790916
J'ai mis à jour ma réponse pour inclure quelques instructions sur la meilleure façon d'appeler un service Web asmx.Si vous êtes toujours coincé, il pourrait être intéressant de faire des recherches sur les services Web asmx. – Adrian