【问题标题】:using the NWS soap server with javax.xml.soap使用带有 javax.xml.soap 的 NWS 肥皂服务器
【发布时间】:2014-07-06 21:30:14
【问题描述】:

我正在尝试使用 NWS 肥皂服务器来获取经纬度预测。我尝试了几种方法,我选择的一种方法使用 javax.xml.soap。当我尝试时,jax-ws 方法立即失败:wsimport -keep http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl。我收到一个错误,表明它无法处理编码。这是我现在正在研究的来源:

package soapexample;
import javax.xml.soap.*;

public class SoapExample {

public static void main(String args[]) throws Exception {
    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    // Send SOAP Message to SOAP Server
    String url = "http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl";
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

    // print SOAP Response
    System.out.print("Response SOAP Message:");
    soapResponse.writeTo(System.out);

    soapConnection.close();
}

private static SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://www.weather.gov/";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("xsi", serverURI);

    /*

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("NDFDgenByDay", "xsi");
    soapBody.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("startDate", "xsi");
    soapBodyElem1.addTextNode("2014-07-06");
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("numDays", "xsi");
    soapBodyElem2.addTextNode("3");
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("Unit", "xsi");
    soapBodyElem3.addTextNode("e");
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("format", "xsi");
    soapBodyElem4.addTextNode("24 hourly");
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("latitude", "xsi");
    soapBodyElem5.addTextNode("38.99");
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("longitude", "xsi");
    soapBodyElem6.addTextNode("-77.01");
    soapMessage.saveChanges();

    /* Print the request message */
    System.out.print("Request SOAP Message:");
    soapMessage.writeTo(System.out);
    System.out.println();

    return soapMessage;
}
`

它几乎可以工作,我得到了这样的回应:

<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:string">SERVER</faultcode>
<faultactor xsi:type="xsd:string"></faultactor>
<faultstring xsi:type="xsd:string">format needs to be either 24 hourly or 12             hourly</faultstring>
<detail xsi:type="xsd:string">input format was &quot;-77.01&quot;</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</code></pre>

此时我迷路了。我找不到我的请求的问题。感谢您的帮助。

【问题讨论】:

    标签: java xml soap


    【解决方案1】:

    在对我的问题几乎没有兴趣之后,我决定再次用谷歌搜索自己,并找到了一篇关于为什么国家气象局无法使用 JAX-WS 的优秀文章。他们甚至提供了一个使用 SAAJ 的工作示例。链接是:

    calling rpc encoded web services

    【讨论】:

      【解决方案2】:

      不确定这是否真的对您有帮助,但我前段时间处理了 NWS 点预测并让我的控件可嵌入:http://www.iontech.org/Weather

      干杯

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-24
        • 1970-01-01
        • 2015-04-05
        相关资源
        最近更新 更多