Точная ошибка - system.net.webexception: удаленный сервер вернул ошибку: (400) Плохой запрос. В System.net.httpwebrequest.getResponse () у меня есть служба REST WCF, размещенную в IIS.. Я создал простое приложение WPF с кнопкой.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.Runtime.Serialization;
using System.Xml;
namespace RestFulDemo
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void RestDemo_Click(object sender, RoutedEventArgs e)
{
string msg="";
HttpWebResponse resp=null;
//WebRequest my = WebRequest.Create(@"http://www.google.com");
//MessageBox.Show(my.ToString());
WebRequest myRequest = WebRequest.Create(@"http://localhost/REST/RestServicesSampl ... mlData/sad");
MessageBox.Show(myRequest.ToString());
//Provides response from a URI.
myRequest.Method = "GET";
myRequest.ContentType = @"text/xml; charset=utf-8";
try
{
resp=myRequest.GetResponse() as HttpWebResponse;
}
catch (WebException c)
{
MessageBox.Show(c.ToString());
}
if (resp.StatusCode == HttpStatusCode.OK)
{
XmlDocument myXMLDocument = new XmlDocument();
XmlReader myXMLReader = new XmlTextReader(resp.GetResponseStream());
myXMLDocument.Load(myXMLReader);
msg= myXMLDocument.InnerText;
}
MessageBox.Show(msg);
}
}
}
< /code>
Почему я получу ошибку в myRequest.getResponse () ..?
Это мой файл .svc.cs < /p>
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace RestServices
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestServicesSample" in both code and config file together.
[ServiceContract]
public interface IRestServicesSample
{
[OperationContract]
[WebGet]
////[WebInvoke(Method = "GET",
//// ResponseFormat = WebMessageFormat.Xml,
//// BodyStyle = WebMessageBodyStyle.Wrapped,
//// UriTemplate = "xml/{id}")]
string XmlData(string id);
//void DoWork();
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{id}")]
string JsonData(string id);
}
}
< /code>
--- Это файл web.config < /p>
`enter code here`
Подробнее здесь: https://stackoverflow.com/questions/199 ... -using-get
Получение 400 http плохого запроса ошибки при доступе к службе WCF REST с помощью GET ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Получение 400 http плохого запроса ошибки при доступе к службе WCF REST с помощью GET
Anonymous » » в форуме C# - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Встреча с ошибкой плохого запроса 400 при создании нового клиента через API Apache FinerAct
Anonymous » » в форуме JAVA - 0 Ответы
- 29 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Встреча с ошибкой плохого запроса 400 при создании нового клиента через API Apache FinerAct
Anonymous » » в форуме JAVA - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-