C#Rest webservice没有反序列化xml正确吗? [英] C# Rest webservice not deserializing xml correct?

查看:102
本文介绍了C#Rest webservice没有反序列化xml正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个休息服务,它与我的get操作完美配合,但我正在尝试实现POST,但是当xml数据到达服务时它看起来像这样(缺少一半的对象和优先级更改为0代替8888):

I have created a rest service and it is working perfectly with my get operation, but i am trying to implement a POST, but when the xml data reaches the service it looks like this (missing half the objects and priority changes to 0 instead of 8888) :

<?xml version="1.0" encoding="utf-8"?>
<DVBAlertDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SessionID>9999</SessionID>
  <Priority>0</Priority>
</DVBAlertDetails>





和Ť他的班级只有dvbtriple和错误为null



我的代码如下:



来电:



and the class just has the dvbtriple and error as null

my code is as follows :

Call :

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "DVBAlert")]
DVBAlertResponse DVBAlert(DVBAlertDetails AlertDetails);



类:


Classes :

[DataContract(Namespace = "")]
public class DVBTriple
{
    [DataMember]
    public int NetworkId { get; set; }

    [DataMember]
    public int ServiceId { get; set; }

    [DataMember]
    public int TransponderId { get; set; }
}

[DataContract(Namespace = "")]
public class Error
{
    [DataMember]
    public string ErrorType { get; set; }

    [DataMember]
    public string ErrorDescription { get; set; }
}

[DataContract(Namespace = "")]
public class DVBAlertDetails
{
    [DataMember]
    public int SessionID { get; set; }

    [DataMember]
    public DVBTriple DVBTriple { get; set; }

    [DataMember]
    public int Priority { get; set; }

    [DataMember]
    public List<Error> Errors { get; set; }
}



XMl发布:


XMl Being posted :

<DVBAlertDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SessionID>9999</SessionID>
  <DVBTriple>
    <NetworkId>3</NetworkId>
    <ServiceId>4</ServiceId>
    <TransponderId>5</TransponderId>
  </DVBTriple>
  <Priority>8888</Priority>
  <Errors>
    <Error>
      <ErrorType>Type</ErrorType>
      <ErrorDescription>Descr</ErrorDescription>
    </Error>
  </Errors>
</DVBAlertDetails>





任何帮助都是apreciated



Any help would be apreciated

推荐答案

使用DataContractSerializer结束而不是来自客户端的xmldocument
Ended up using a DataContractSerializer instead of a xmldocument from the clientside


这篇关于C#Rest webservice没有反序列化xml正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆