所以我试图用PHP和SOAP调用web服务,但它似乎没有正确地做,我无法弄清楚为什么。这是PHP:
$client = new SoapClient($wsdl, array('trace' => 1));
print_r($client->__getFunctions());
$params->param1 = "satsys";
$params->param2 = "0A259772-983C-4EFB-834E-6184F8E9F4E7";
$params->param3 = null;
$response = $client->SetHardwareProfile($params);
var_dump($response);
echo "Last Request: ".$client->__getLastRequest();
echo "Last Response: ".$client->__getLastResponse();
这是输出:
Array
(
[0] => ValidateLicenseKeyResponse ValidateLicenseKey(ValidateLicenseKey $parameters)
[1] => CreateProviderResponse CreateProvider(CreateProvider $parameters)
[2] => SetHardwareProfileResponse SetHardwareProfile(SetHardwareProfile $parameters)
[3] => UpdateCurrentVersionResponse UpdateCurrentVersion(UpdateCurrentVersion $parameters)
[4] => SoftwareUpdateAvailableResponse SoftwareUpdateAvailable(SoftwareUpdateAvailable $parameters)
[5] => GetSoftwareUpdateResponse GetSoftwareUpdate(GetSoftwareUpdate $parameters)
)
object(stdClass)#3 (1) {
["SetHardwareProfileResult"]=>
bool(false)
}
和XML:
<?xml version="1.0" encoding="UTF-8"?>
<!--Last Request:-->
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:SetHardwareProfile/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<!--Last Response:-->
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SetHardwareProfileResponse xmlns="http://tempuri.org/">
<SetHardwareProfileResult>false</SetHardwareProfileResult>
</SetHardwareProfileResponse>
</s:Body>
</s:Envelope>
现在从我所看到的,这是一个问题的请求,因为它不是那样,应该看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:SetHardwareProfile>
<customerId xsi:type="xsd:string">satsys</customerId>
<providerGuid xsi:type="xsd:string">0A259772-983C-4EFB-834E-6184F8E9F4E7</providerGuid>
<other xsi:type="xsd:string"></other>
</ns1:SetHardwareProfile>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是服务合同,为了更好的衡量标准(用C#编写):
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Collections.Generic;
namespace ProviderSync
{
[ServiceContract]
public interface IProviderSync
{
[OperationContract]
bool SetHardwareProfile(String customerId, String providerGuid, List<Device> hardware);
}
}
答案 0 :(得分:0)
好的,问题是,使用SOAP时,与其他语言不同,参数必须具有其确切的名称。所以上面的PHP代码块实际应该是这样读的:
$client = new SoapClient($wsdl, array('trace' => 1));
print_r($client->__getFunctions());
$params->customerId = "satsys";
$params->providerGuid = "0A259772-983C-4EFB-834E-6184F8E9F4E7";
$params->hardware = null;
$response = $client->SetHardwareProfile($params);
var_dump($response);
echo "Last Request: ".$client->__getLastRequest();
echo "Last Response: ".$client->__getLastResponse();
因为它们被服务合同声明为:
bool SetHardwareProfile(String customerId, String providerGuid, List<Device> hardware);
我不确定为什么会出现这种情况,或者在所有形式的SOAP调用中都是这种情况,但是这种更改为我解决了这个问题。