我有一个带有以下签名的 WCF 服务方法:
public string CTNotification(JSONRecordingCompletedNotification content)
{
我想创建一个客户端并使用它。我已经编写了以下代码,但它给出了错误:
using (StreamReader sr = new StreamReader(Server.MapPath("~/json.txt")))
{
string serviceBaseUrl = ConfigurationManager.AppSettings["serviceurl"].ToString() + "CTNotification";
string conversationId = ConfigurationManager.AppSettings["conversationId"].ToString();
String line = sr.ReadToEnd();
string jsonText = line;
string body = jsonText;
JSONRecordingCompletedNotification RecordingCompletedNotification = new JavaScriptSerializer().Deserialize<JSONRecordingCompletedNotification>(body);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceBaseUrl);
request.Method = "POST";
request.ContentType = "application/json";
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(RecordingCompletedNotification);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Label1.Text = response.ToString();
}
我收到以下错误:
The remote server returned an error: (400) Bad Request.