私は、コードは次のようになり、私のクライアントからの404エラーを返すPUTリクエストを持っている:WCF WebサービスへのPUTメソッドの "404"ですか?
{
string uriupdatestudent = string.Format("http://localhost:8000/Service/Student/{0}/{1}/{2}", textBox16.Text, textBox17.Text, textBox18.Text);
byte[] arr = Encoding.UTF8.GetBytes(uriupdatestudent);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriupdatestudent);
req.Method = "PUT";
req.ContentType = "application/xml";
req.ContentLength = arr.Length;
using (Stream reqStrm = req.GetRequestStream())
{
reqStrm.Write(arr, 0, arr.Length);
reqStrm.Close();
}
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
MessageBox.Show(resp.StatusDescription);
resp.Close();
}
}
OperationContractおよびサービスは、次のようになります。あなたはURIに基づい
[OperationContract]
[WebInvoke(Method = "PUT", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/Student")]
void UpdateStudent(Student student);
public void UpdateStudent(Student student)
{
var findStudent = students.Where(s => s.StudentID == student.StudentID).FirstOrDefault();
if (findStudent != null)
{
findStudent.FirstName = student.FirstName;
findStudent.LastName = student.LastName;
}
}
[DataContract(Name="Student")]
public class Student
{
[DataMember(Name = "StudentID")]
public string StudentID { get; set; }
[DataMember(Name = "FirstName")]
public string FirstName { get; set; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
[DataMember(Name = "TimeAdded")]
public DateTime TimeAdded;
public string TimeAddedString
FWIWでは、 'using'が誤ってreqStream ...を2回終了して一般的に見た目をよくしています。 –
あなたの権利ではありますが、私はちょうど投稿をテストし、置いて、取得し、残りの部分を削除します。今のところ4のうち3つ:)ただ今置く必要があります。 –
これについての入札者はありませんか? –