好的,所以我有一个 MediaTypeFormatter:
public class iOSDeviceXmlFormatter : BufferedMediaTypeFormatter
{
public iOSDeviceXmlFormatter() {
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml"));
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
}
public override bool CanReadType(Type type) {
if (type == typeof(iOSDevice)) {
return true;
}
return false;
}
public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {
iOSDevice device = null;
using (XmlReader reader = XmlReader.Create(readStream)) {
if (reader.ReadToFollowing("iOSDevice")) {
if (!reader.IsEmptyElement) {
device = new iOSDevice();
... do processing here ...
}
}
}
readStream.Close();
return device;
}
我有这个动作来处理 PUT:
public void Put(string id, iOSDevice model)
{
}
我也试过这个:
public void Put(string id, [FromBody]iOSDevice model)
{
}
我试过这个:
public void Put(string id, [FromBody]string value)
{
}
当我这样做时,这些都不起作用:
string data = "<iOSDevice>xml_goes_here</iOSDevice>";
WebClient client = new WebClient();
client.UploadString(url, "PUT", data);
该操作拒绝触发我的 iOSDeviceXmlFormatter,它甚至不会将其读取为 [FromBody] 字符串。你怎么得到这个东西的地图?
谢谢,
艾莉森