2015-09-02 35 views
1

每个人。 我正在使用URN使用消息合约和wcf的旧服务,我有这个小但非常棘手的不方便。更改节点元素WCF中的URN

<soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UMARKETSPIWS:v2" xmlns:gps="http://schemas.datacontract.org/2004/07/GPS"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <urn:CreditAirtime> 
     <!--Optional:--> 
     <urn:transactionId>321321</urn:transactionId> 
     <!--Optional:--> 
     <urn:extraParameters> 
      <!--Zero or more repetitions:--> 
      <gps:KeyValuePairs> 
       <!--Optional:--> 
       <gps:key>?</gps:key> 
       <!--Optional:--> 
       <gps:value>?</gps:value> 
      </gps:KeyValuePairs> 
     </urn:extraParameters> 
     <!--Optional:--> 
     <urn:msisdn>50370823063</urn:msisdn> 
     <!--Optional:--> 
     <urn:amount>5</urn:amount> 
     </urn:CreditAirtime> 
    </soapenv:Body> 
</soapenv:Envelope> 

我想改变GPS:标签瓮:在extraParameters节例如:通过添加[MessageBodyMember(NAME = “键”

<soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UMARKETSPIWS:v2" xmlns:gps="http://schemas.datacontract.org/2004/07/GPS"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <urn:CreditAirtime> 
     <!--Optional:--> 
     <urn:transactionId>321321</urn:transactionId> 
     <!--Optional:--> 
     <urn:extraParameters> 
      <!--Zero or more repetitions:--> 
      <urn:KeyValuePairs> 
       <!--Optional:--> 
       <urn:key>?</gps:key> 
       <!--Optional:--> 
       <urn:value>?</gps:value> 
      </urn:KeyValuePairs> 
     </urn:extraParameters> 
     <!--Optional:--> 
     <urn:msisdn>50370823063</urn:msisdn> 
     <!--Optional:--> 
     <urn:amount>5</urn:amount> 
     </urn:CreditAirtime> 
    </soapenv:Body> 
</soapenv:Envelope> 

我alredy尝试,令= 0,命名空间=“urn:”)]并不会工作一切工作正常,但我真的不知道从哪里开始。

接口和类在这里。 http://pastebin.com/dtjmXQaz

+2

命名空间应该是urn:UMARKETSPIWS:v2而不是urn:“'。 'urn:'只是实际命名空间的查找[前缀](http://www.w3schools.com/xml/xml_namespaces.asp)。除此之外,你能分享你的类,包括'KeyValuePairs'和'extraParameters'吗? – dbc

+0

Alredy更正了urn名称空间,但仍然可以修改keyvalpairs的名称空间,这里是接口和类http://pastebin.com/dtjmXQaz谢谢。 – NeKSV

回答

0

MessageContract属性只控制SOAP格式为对应于SOAP消息信封一个类型 - 直接在OperationContract出现的类型之一。对于未映射到SOAP消息但仅由根消息类型引用的类型,您需要使用data contract attributes。因此:

[DataContract(Namespace = "urn:UMARKETSPIWS:v2")] 
    public class KeyValuePair 
    { 
     [DataMember(Name = "key", Order = 0)] 
     public string key { get; set; } 

     [DataMember(Name = "value", Order = 1)] 
     public string value { get; set; } 
    } 

实际上,对于简单的信息,你不需要的SOAP消息格式或安全性,你可以经常只使用数据合同属性的精确控制。见Using Message ContractsSpecifying Data Transfer in Service Contracts

+0

非常感谢你,现在我明白了这两种契约之间的区别 – NeKSV