亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

取消編組名稱間隔 SOAP XML 參數的問題

取消編組名稱間隔 SOAP XML 參數的問題

慕虎7371278 2022-09-07 21:17:13
我在處理 SOAP 請求時遇到問題。我可以從信封中讀取所有內容,但無法解析名稱空間修飾參數(cs:measurand)。在這里,您可以找到 SOAP 信封:<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cs/2012/06/" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    <soap:Header>        <cs:identity>17083A00001101</cs:identity>        <a:From>            <a:Address>http://172.0.0.0:9080</a:Address>        </a:From>        <a:MessageID>urn:uuid:xxxxxxxxxxxx</a:MessageID>        <a:ReplyTo>            <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>        </a:ReplyTo>        <a:To>http://172.0.0.0:8080/ws/ocp</a:To>        <a:Action>/MValues</a:Action>    </soap:Header>    <soap:Body>        <cs:mValuesRequest>            <cs:id>1</cs:id>            <cs:transactionId>1881</cs:transactionId>            <cs:values>                <cs:timestamp>2019-03-07T13:41:52.405Z</cs:timestamp>                <cs:value cs:measurand="e.a.i.r" cs:unit="Wh">300</cs:value>                <cs:value cs:measurand="c.i" cs:unit="Amp">38.5</cs:value>                <cs:value cs:measurand="v" cs:unit="Volt">399.5</cs:value>                <cs:value cs:measurand="p.a.i" cs:unit="W">15380</cs:value>                <cs:value cs:measurand="t" cs:unit="Celsius">35</cs:value>            </cs:values>        </cs:mValuesRequest>    </soap:Body></soap:Envelope>以下是接收請求的服務:    @Action("/MValues")    @ResponsePayload    public JAXBElement<MValuesResponse> receive(@RequestPayload MValuesRequest request,            MessageContext messageContext) {....    }
查看完整描述

2 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

試試這個,


MValuesRequest.java


@XmlRootElement(name="cs:mValuesRequest")

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name ="ValuesRequest", propOrder = { "id", "transactionId", "values" })

public class MValuesRequest {


    @XmlElement(name="cs:id")

    protected int id;


    @XmlElement(name="cs:transactionId")

    protected Integer transactionId;


    @XmlElement(name="cs:values")

    protected Values values;

//  getters and setters...

}

價值觀.java


@XmlRootElement(name="cs:values")

public class Values{


    @XmlElement(name="cs:timestamp")

    protected String timestamp;


    @XmlElement(name="cs:value")

    protected List<Value> value;

//  getters and setters...

}

值.java


@XmlRootElement(name="cs:value")

public class value{


    @XmlAttribute(name="measurand" namespace="http://www.w3.org/XML/1998/namespace")

    protected String measurand;


    @XmlAttribute(name="unit" namespace="http://www.w3.org/XML/1998/namespace")

    protected String unit;


    @XmlValue

    protected String elementValue;

//  getters and setters...

}


查看完整回答
反對 回復 2022-09-07
?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

我終于可以解決這個問題,非常感謝Rathnayake。


我不必添加@XmlRootElement而只需將命名空間參數添加到@XmlAttribute。


所以目前我的 XML 參數如下所示:


    @XmlAttribute(name = "context", namespace="urn://Ocpp/Cs/2012/06/")

    protected ReadingContext context;

    @XmlAttribute(name = "format", namespace="urn://Ocpp/Cs/2012/06/")

    protected ValueFormat format;

    @XmlAttribute(name = "measurand", namespace="urn://Ocpp/Cs/2012/06/")

    protected Measurand measurand;

    @XmlAttribute(name = "location", namespace="urn://Ocpp/Cs/2012/06/")

    protected Location location;

    @XmlAttribute(name = "unit", namespace="urn://Ocpp/Cs/2012/06/")

    protected UnitOfMeasure unit;

請記住,這是我的 SOAP 標頭:


<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:cs="urn://Ocpp/Cs/2012/06/" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

我添加了命名空間=“...”值 xmlns:cs=“...”從標頭。


查看完整回答
反對 回復 2022-09-07
  • 2 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號