传递“布尔数组” NOAA 的 SOAP 服务

发布于 2024-11-28 23:10:43 字数 1077 浏览 2 评论 0原文

我正在尝试使用 SOAPClient 查询 NOAA SOAP API 以获取某些特定信息。根据 此博客,对服务的典型查询如下所示帖子

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen');
$result = $client->NDFDgen(40.7893,-96.6938,'glance','2007-04-20T00:00','2007-04-21T00:00',NULL);

又好又简单。但是,查看文档显示最后一个参数。可以采用发送到服务器的布尔值数组来打开响应中的特定内容。如果正确完成,查询最终看起来像这样

所以,当然,我尝试类似的操作...

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen');
$result = $client->NDFDgen(40.7893,-96.6938,'time-series','2007-04-20T00:00','2007-04-21T00:00', array('mint' => 1, 'maxt' => 1));

请注意,我还必须将参数 3 更改为“时间序列”,因为“浏览”只是对其返回的内容进行硬编码(完全忽略第五个参数)。在任何情况下,上述代码都会导致服务器发回空白响应。我在第六个参数中尝试了各种其他方法,但没有成功。

那么,有什么大创意呢?如何为 API 提供预期的“布尔数组”?

I'm attempting to use SOAPClient to query the NOAA SOAP API for some specific information. A typical query to the service goes something like this, according to this blog post:

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen');
$result = $client->NDFDgen(40.7893,-96.6938,'glance','2007-04-20T00:00','2007-04-21T00:00',NULL);

Nice and easy. However, taking a look at the documentation shows that the last param. can take an array of booleans that is sent to the server to turn on specific things in the response. When done correctly, the query ends up looking like this.

So of course, I try something like...

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen');
$result = $client->NDFDgen(40.7893,-96.6938,'time-series','2007-04-20T00:00','2007-04-21T00:00', array('mint' => 1, 'maxt' => 1));

Notice that I also had to change param 3 to 'time-series', as 'glance' simply hardcodes what it returns (ignoring the fifth param completely). In any case the above code causes the server sends back a blank response. I've tried various other things in that sixth param with no luck.

So, what's the big idea? How do I give the API an 'array of booleans' like it expects?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮凉 2024-12-05 23:10:43

使用简单的方式发送请求中的XML参数。对于布尔值,您可以直接使用“true”。

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen',array('trace' => 1));
$param1 = new SoapParam(40.7893, "latitude");;
$param2 = new SoapParam(-96.6938, "longitude");;
$xmlDocument = '<product xmlns:dwml="http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">glance</product>';
$xmlvar = new SoapVar($xmlDocument,XSD_ANYXML);
$param3 = new SoapParam($xmlvar, "product");;
$param4 = new SoapParam("2011-09-06T00:00", "startTime");;
$param5 = new SoapParam("2011-09-07T00:00", "endTime");;
$xmlDocument = '<weatherParameters xmlns:dwml="http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
<maxt xsi:type="xsd:boolean">true</maxt>
<mint xsi:type="xsd:boolean">true</mint>
</weatherParameters>';
$xmlvar = new SoapVar($xmlDocument,XSD_ANYXML);
$param6 = new SoapParam($xmlvar, "weatherParameters");;
$result = $client->NDFDgen($param1,$param2,$param3,$param4,$param5,$param6);
echo "REQUEST:".$client->__getLastRequest()."<br>"; 
print_r($result);

Use Simple way to send the XML parameter in the request. For Boolean values you can directly use "true".

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen',array('trace' => 1));
$param1 = new SoapParam(40.7893, "latitude");;
$param2 = new SoapParam(-96.6938, "longitude");;
$xmlDocument = '<product xmlns:dwml="http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">glance</product>';
$xmlvar = new SoapVar($xmlDocument,XSD_ANYXML);
$param3 = new SoapParam($xmlvar, "product");;
$param4 = new SoapParam("2011-09-06T00:00", "startTime");;
$param5 = new SoapParam("2011-09-07T00:00", "endTime");;
$xmlDocument = '<weatherParameters xmlns:dwml="http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
<maxt xsi:type="xsd:boolean">true</maxt>
<mint xsi:type="xsd:boolean">true</mint>
</weatherParameters>';
$xmlvar = new SoapVar($xmlDocument,XSD_ANYXML);
$param6 = new SoapParam($xmlvar, "weatherParameters");;
$result = $client->NDFDgen($param1,$param2,$param3,$param4,$param5,$param6);
echo "REQUEST:".$client->__getLastRequest()."<br>"; 
print_r($result);
装纯掩盖桑 2024-12-05 23:10:43

您似乎缺少 unitType $Unit,如 __getFunctions() 中所述。您只需将其设置为 'e' (美国)或 'm' (公制读数)。看起来它还要求您为所有返回值定义布尔值......而不仅仅是您想要的值。因此,您需要

$PARAMS = array('appt' => false,
'conhazo' => false,
'critfireo' => false,
'cumw34' => false,
'cumw50' => false,
'cumw64' => false,
'dew' => false,
'dryfireo' => false,
'iceaccum' => false,
'icons' => false,
'incw34' => false,
'incw50' => false,
'incw64' => false,
'maxrh' => false,
'maxt' => true,
'minrh' => false,
'mint' => true,
'phail' => false,
'pop12' => false,
'prcpabv14d' => false,
'prcpabv30d' => false,
'prcpabv90d' => false,
'prcpblw14d' => false,
'prcpblw30d' => false,
'prcpblw90d' => false,
'precipa_r' => false,
'ptornado' => false,
'ptotsvrtstm' => false,
'ptstmwinds' => false,
'pxhail' => false,
'pxtornado' => false,
'pxtotsvrtstm' => false,
'pxtstmwinds' => false,
'qpf' => false,
'rh' => false,
'rx' => false,
'sky' => false,
'sky_r' => false,
'snow' => false,
'td_r' => false,
'temp' => false,
'temp_r' => false,
'tmpabv14d' => false,
'tmpabv30d' => false,
'tmpabv90d' => false,
'tmpblw14d' => false,
'tmpblw30d' => false,
'tmpblw90d' => false,
'waveh' => false,
'wdir' => false,
'wdir_r' => false,
'wgust' => false,
'wspd' => false,
'wspd_r' => false,
'wwa' => false,
'wx' => false);

在声明 unitType 后定义并将其添加到您的调用中:

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl');
$result = $client->NDFDgen(40.7893,-96.6938,'time-series',NULL,NULL,'e',$PARAMS);

You seem to be missing the unitType $Unit as described in __getFunctions(). You'll just need to set it to 'e' for US or 'm' for metric readings. It looks like it also requires that you define booleans for ALL of the return values... not just the ones you want. Therefore, you'd want to define

$PARAMS = array('appt' => false,
'conhazo' => false,
'critfireo' => false,
'cumw34' => false,
'cumw50' => false,
'cumw64' => false,
'dew' => false,
'dryfireo' => false,
'iceaccum' => false,
'icons' => false,
'incw34' => false,
'incw50' => false,
'incw64' => false,
'maxrh' => false,
'maxt' => true,
'minrh' => false,
'mint' => true,
'phail' => false,
'pop12' => false,
'prcpabv14d' => false,
'prcpabv30d' => false,
'prcpabv90d' => false,
'prcpblw14d' => false,
'prcpblw30d' => false,
'prcpblw90d' => false,
'precipa_r' => false,
'ptornado' => false,
'ptotsvrtstm' => false,
'ptstmwinds' => false,
'pxhail' => false,
'pxtornado' => false,
'pxtotsvrtstm' => false,
'pxtstmwinds' => false,
'qpf' => false,
'rh' => false,
'rx' => false,
'sky' => false,
'sky_r' => false,
'snow' => false,
'td_r' => false,
'temp' => false,
'temp_r' => false,
'tmpabv14d' => false,
'tmpabv30d' => false,
'tmpabv90d' => false,
'tmpblw14d' => false,
'tmpblw30d' => false,
'tmpblw90d' => false,
'waveh' => false,
'wdir' => false,
'wdir_r' => false,
'wgust' => false,
'wspd' => false,
'wspd_r' => false,
'wwa' => false,
'wx' => false);

and then add it to your call after declaring the unitType:

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl');
$result = $client->NDFDgen(40.7893,-96.6938,'time-series',NULL,NULL,'e',$PARAMS);
一直在等你来 2024-12-05 23:10:43

如果您查看该服务的描述,您会发现最后一个参数是 NOAA 描述的复杂数据类型。您可以创建weatherParametersType的实例,然后直接修改其成员。 (例如wParams.pop12=True

If you look at the description of the service, you will see that the last parameter is a complex data type, described by NOAA. You can create an instance of the weatherParametersType, and then modify its members directly. (e.g. wParams.pop12=True)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文