Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/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
C# 为RESTful WCF C构造XML请求#_C#_Wcf - Fatal编程技术网

C# 为RESTful WCF C构造XML请求#

C# 为RESTful WCF C构造XML请求#,c#,wcf,C#,Wcf,我正在尝试创建RESTful WCF服务。我希望Service.svc上的XML如下所示 <Organization> <Employees> <Employee>Test1</Employee> <Employee>Test2</Employee> </Employees> </Organization> 测试1 测试2 我想使用WCF C#类属性创建如上所述的XML结构 下面是我试过的 Pu

我正在尝试创建RESTful WCF服务。我希望Service.svc上的XML如下所示

<Organization>
<Employees>
<Employee>Test1</Employee>
<Employee>Test2</Employee>
</Employees>
</Organization>

测试1
测试2
我想使用WCF C#类属性创建如上所述的XML结构

下面是我试过的

Public class Organization
{
   Public List<Employee> Employees {get;set;}
}

Public class Employee
{
  Public string Name {get;set;}
}
公共类组织
{
公共列表雇员{get;set;}
}
公营雇员
{
公共字符串名称{get;set;}
}

我做错了什么。

检查
DataContract
属性和相应的
DataMember

例如:

namespace MyTypes
{
    [DataContract]
    public class PurchaseOrder
    {
        private int poId_value;

        // Apply the DataMemberAttribute to the property.
        [DataMember]
        public int PurchaseOrderId
        {

            get { return poId_value; }
            set { poId_value = value; }
        }
    }
}
或者在您的情况下:

[DataContract]
Public class Organization
{
   [DataMember]
   Public List<Employee> Employees {get;set;}
}

[DataContract]
Public class Employee
{
  [DataMember]
  Public string Name {get;set;}
}

检查
DataContract
属性和相应的
DataMember

例如:

namespace MyTypes
{
    [DataContract]
    public class PurchaseOrder
    {
        private int poId_value;

        // Apply the DataMemberAttribute to the property.
        [DataMember]
        public int PurchaseOrderId
        {

            get { return poId_value; }
            set { poId_value = value; }
        }
    }
}
或者在您的情况下:

[DataContract]
Public class Organization
{
   [DataMember]
   Public List<Employee> Employees {get;set;}
}

[DataContract]
Public class Employee
{
  [DataMember]
  Public string Name {get;set;}
}

我不想添加名称节点。如何在employees标记中包含员工列表,因此应该是
Test1Test2
查看带有
CollectionDataContract
属性的更新版本我不想添加名称节点。我怎样才能在employees标记中包含员工列表,所以它应该是
Test1Test2
查看带有
CollectionDataContract
属性的更新版本您不能这样做。每个DataMember都有一个name属性。如果不设置该属性,则其默认值为应用该属性的目标的名称。您不能这样做。每个DataMember都有一个name属性。如果未设置该属性,则其默认值为应用该属性的目标的名称。