Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web API将不接受XML_Xml_Asp.net Web Api - Fatal编程技术网

Web API将不接受XML

Web API将不接受XML,xml,asp.net-web-api,Xml,Asp.net Web Api,我正在尝试使用web API创建一个web服务,它将接受来自SAP PI系统的XML文件。我有XML格式,但web服务不接受它 <?xml version="1.0" encoding="UTF-8"?> <ns0:ContactUs xmlns:ns0="http://customdomain.com/ContactUs"> <userId></userId> <firstName></firstName> <

我正在尝试使用web API创建一个web服务,它将接受来自SAP PI系统的XML文件。我有XML格式,但web服务不接受它

<?xml version="1.0" encoding="UTF-8"?>
<ns0:ContactUs xmlns:ns0="http://customdomain.com/ContactUs">
 <userId></userId>
 <firstName></firstName>
 <lastName></lastName>
 <e_mail></e_mail>
 <gsm></gsm>
 <country></country>
 <city></city>
 <subject></subject>
 <type></type>
 <detail></detail>
 <message></message>
 <orderId></orderId>
 <storeName></storeName>
</ns0:ContactUs>

}

尝试将模型属性的名称与XML字段名称(即模型的orderID和XML的orderID)匹配。看看这会不会改变什么,已经是这样了。我更改了XML,使其与字母大小写匹配,但不起作用。
public HttpResponseMessage PostCustomerRecord(CustomerRecord customerrecord)
    {
        if (ModelState.IsValid && customerrecord != null)
        {
            db.CustomerRecords.Add(customerrecord);
            db.SaveChanges();
            try
            {
                Mailing.SendMail.Send();
            }
            catch (System.Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customerrecord);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = customerrecord.Id }));
            return response;
        }
        else
        {
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
    }

namespace ContactUs.Models
{
[DataContract(Namespace="http://customdomain.com/ContactUs", Name="ContactUs")]
public class CustomerRecord
{
    [Key]
    public int Id { get; set; }

    [Required]
    [DataMember(Name="type")]
    [StringLength(50)]
    public string type { get; set; }

    [Required]
    [DataMember]
    [StringLength(500)]
    public string subject { get; set; }

    [Required]
    [DataMember]
    public string message { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string firstName { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string lastName { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string country { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string city { get; set; }

    [Required]
    [DataMember]
    [StringLength(20)]
    public string gsm { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string e_mail { get; set; }

    [Required]
    [DataMember]
    [StringLength(50)]
    public string detail { get; set; }

    [StringLength(50)]
    [DataMember]
    public string storeName { get; set; }

    [StringLength(50)]
    [DataMember]
    public string userID { get; set; }

    [StringLength(50)]
    [DataMember]
    public string orderID { get; set; }

}