誰でもこれを解決できますか? ほとんど同じ 2 つのサービスがありますが、更新が完了した後に get 要求で 1 つが失敗しますか?
public void UpdateCarType(string carregistration, CarType cartype)
{
var findcar = cartypes.Where(s => s.CarRegistration == carregistration).FirstOrDefault();
if (findcar != null)
{
findcar.CarRegistration = cartype.CarRegistration;
findcar.CarModel = cartype.CarModel;
findcar.CarMake = cartype.CarMake;
findcar.CarColour = cartype.CarColour;
findcar.CarEngineSize = cartype.CarEngineSize;
findcar.CarHireCostPerDay = cartype.CarHireCostPerDay;
}
これは操作コントラクトです:
[OperationContract]
[WebInvoke(Method = "PUT", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/UpdateCarType/{carregistration}")]
void UpdateCarType(string carregistration, CarType cartype);
これは、クライアント側の更新および取得要求です。
アップデート:
private void button29_Click(object sender, RoutedEventArgs e)
{
string uriupdatestaff = string.Format("http://localhost:8002/Service/UpdateCarType/{0}", textBox30.Text);
StringBuilder sb = new StringBuilder();
sb.Append("<CarType>");
sb.AppendLine("<CarRegistration>" + textBox30.Text + "</CarRegistration>");
sb.AppendLine("<CarColour>" + this.comboBox6.Text + "</CarColour>");
sb.AppendLine("<CarEngineSize>" + this.comboBox7.Text + "</CarEngineSize>");
sb.AppendLine("</CarType>");
string NewStudent = sb.ToString();
byte[] arr = Encoding.UTF8.GetBytes(NewStudent);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriupdatestaff);
req.Method = "PUT";
req.ContentType = "application/xml";
req.ContentLength = arr.Length;
Stream reqStrm = req.GetRequestStream();
reqStrm.Write(arr, 0, arr.Length);
reqStrm.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
MessageBox.Show(resp.StatusDescription);
reqStrm.Close();
resp.Close();
}
得る:
{
string uriGetdates = "http://localhost:8002/Service/CarType";
XDocument xDoc = XDocument.Load(uriGetdates);
var dates = xDoc.Descendants("CarType")
.Select(n => new
{
CarRegistration = n.Element("CarRegistration").Value,
CarModel = n.Element("CarModel").Value,
CarMake = n.Element("CarMake").Value,
CarColour = n.Element("CarColour").Value,
CarEngineSize = n.Element("CarEngineSize").Value,
CostPerDay = n.Element("CarHireCostPerDay").Value,
})
.ToList();
dataGrid10.ItemsSource = dates;
}
私の自動的な考えは、残りのフィールドがnullである車の色と車のエンジンサイズのみを定義しているためですが、まったく同じ操作ですが、顧客ではこれを行わず、1つのフィールドのみを更新してもリストをデータグリッドに返します.
Object reference not set to an instance of an object.
更新された cartype を再出品しようとするとエラーが発生します。