如何设置Array类型的属性

时间:2015-01-13 15:36:58

标签: c# web-services soap xml-serialization

我的应用程序中有一个SOAP Header。我需要在 ClientContext

中添加一个新值item,其值为 pcimask ,值为 true

我的clientcontext在填充时看起来像这样:

{EvryCardManagement.ws.card.DCSSCardCreate_V3_0.ClientContextType}
channel: "NBA"
channelField: "NBA"
credentials: "token string"
credentialsField: "string"
customerid: ""
customeridField: ""
ip: "123.456.789.123"
ipField: "123.456.789.123"
item: null
itemField: null
locale: null
localeField: null
orgid: "123456"
orgidField: "123456"
orgunit: "123456"
orgunitField: "123456"
userid: "name"
useridField: "name"

之后,我需要添加一个名为pcimask的新元素,其值为 true

wsdl中的

更新:有一个名为item的元素(在ClientContext内),我需要将它添加到SOAP消息头中,如下所示:{ {1}}

在Web服务WSDL中,我需要设置的<item key="pcimask" value="true"/>定义如下:

item

所以在我设置这些值的代码中我有这个:

private itemType[] itemField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("item", IsNullable=true)]
public itemType[] item {
    get {
        return this.itemField;
        }
    set {
        this.itemField = value;
        }
    }

ClientContextType clientContext = new ClientContextType(); clientContext.userid = edb_service[0].userid; clientContext.credentials = Common.SOToken; //clientContext.pc clientContext.orgid = edb_service[0].orgid; clientContext.orgunit = edb_service[0].orgunit; clientContext.customerid = ""; clientContext.channel = edb_service[0].channel; clientContext.ip = edb_service[0].ip; 元素之后我想设置项目:

ip

但它不会编译,因为它像数组或列表一样,我需要添加一个新项目,以便它显示在标题xml中,如下所示:

clientContext.item = edb_service[0].pcimask;

我需要做什么?

1 个答案:

答案 0 :(得分:1)

您必须执行类似

的操作
clientContext.item = new itemType[]{new itemType{key="pcimask", value="true"}};

item是一个数组。您必须创建一个数组,使用适当的数据填充它,然后使用该数组设置item。以上是这样做的捷径。一步一步:

itemType it = new itemType();
it.key = "pcimask";
it.value = "true";
itemType[] itArray = new itemType[];
itArray[0] = it;
clientContext.item = itArray;
BTW请注意,这与SOAP标头无关。你的问题只是你不知道如何设置数组。