如何创建PHP SOAP请求和响应

如何创建PHP SOAP请求和响应,php,xml,soap,Php,Xml,Soap,我正在使用API,我对PHP SOAP还不熟悉。。我试图创建一个请求来获取车辆值,并希望获取响应值 下面是一个SOAP1.1请求示例。显示的占位符需要替换为实际值 POST /vehicles/vehicle.asmx HTTP/1.1 Host: webservice.nada.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://webservice.nada.com/getD

我正在使用API,我对PHP SOAP还不熟悉。。我试图创建一个请求来获取车辆值,并希望获取响应值

下面是一个SOAP1.1请求示例。显示的占位符需要替换为实际值

POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
    <vehicleRequest>
    <Vin>string</Vin>
    <Region>int</Region>
    <Mileage>int</Mileage>
  </vehicleRequest>
</getDefaultVehicleAndValueByVin>
这是我尝试过的,但没有结果-

$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));

 $params = new \SoapVar("<vehicleRequest><Vin>5YFBURHE3FP331896</Vin><Region>10</Region><Mileage>100000</Mileage></vehicleRequest>", XSD_ANYXML);
 $result = $client->Echo($params);
$clientV=new-soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl,数组(//Stuff for development.'trace'=>1,'exceptions'=>1,'cache_wsdl'=>0));
$params=new\SoapVar(“5yfburhe3fp3318961010000”,XSD_ANYXML);
$result=$client->Echo($params);
我尝试过的另一种方法在解析WSDL时出错

$wsdl = '
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
      <vehicleRequest>
        <Vin>5YFBURHE3FP331896</Vin>
        <Region>1</Region>
        <Mileage>100</Mileage>
      </vehicleRequest>
    </getDefaultVehicleAndValueByVin>
  </soap:Body>
</soap:Envelope>
';

try {

     $clientC = @new SOAPClient($wsdl);  for $wsdl

     $response = $clientC->getDefaultVehicleAndValueByVin(array('key' => 'val')); 

     } catch (Exception $e) {  

     echo $e->getMessage(); 

}

die(var_dump($response));
$wsdl=
POST/vehicles/vehicle.asmx HTTP/1.1
主持人:webservice.nada.com
内容类型:text/xml;字符集=utf-8
内容长度:长度
SOAPAction:“http://webservice.nada.com/getDefaultVehicleAndValueByVin"
5YFBURHE3FP331896
1.
100
';
试一试{
$clientC=@newsoapclient($wsdl);对于$wsdl
$response=$clientC->getDefaultVehicleAndValueByVin(数组('key'=>'val');
}捕获(例外$e){
echo$e->getMessage();
}
模具(var_转储($response));
这是我得到的错误-


SOAP-ERROR:解析WSDL:无法从'POST/vehicles/vehicle.asmx HTTP/1.1主机:webservice.nada.com内容类型:text/xml;charset=utf-8内容长度:长度SOAPAction:“5YFBURHE3FP331896 1 100”:未能加载外部实体“POST/vehicles/vehicle.asmx HTTP/1.1主机:webservice.nada.com内容类型:text/xml;charset=utf-8内容长度:长度SOAPAction:”“

类似的内容应该可以帮助您开始。我不是100%熟悉NADAAPI,所以我不知道一些参数的有效值是什么。。。您必须填写正确的值(例如令牌、期间、车辆类型和区域)


您面临的具体问题是什么?到目前为止你试过什么?恐怕这既不是一个“什么是最好的教程”也不是一个“请给我写一些代码”的服务——你肯定已经知道了。鉴于你之前的问题,你有足够的php技能来尝试一下!是的,我不是在找人帮我写代码。我在找如何在php脚本中构造XML调用。使用soapurl调用,我不确定如何包含XML调用。再说一次,我从来没有使用过SOAP,所以我只是在寻找一些方向或起点,我用我的尝试更新了这个问题,但没有返回任何结果。我是否需要将所有XML添加到$params中?分配给变量
$wsdl
的不是wsdl文档,而是HTTP请求。您需要加载一个适当的WSDL文档。@BrianDriscoll谢谢,我发现这是一个示例,他们将$WSDL作为xml数据。我正在努力寻找一种在php脚本中请求xml数据的方法
$wsdl = '
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
      <vehicleRequest>
        <Vin>5YFBURHE3FP331896</Vin>
        <Region>1</Region>
        <Mileage>100</Mileage>
      </vehicleRequest>
    </getDefaultVehicleAndValueByVin>
  </soap:Body>
</soap:Envelope>
';

try {

     $clientC = @new SOAPClient($wsdl);  for $wsdl

     $response = $clientC->getDefaultVehicleAndValueByVin(array('key' => 'val')); 

     } catch (Exception $e) {  

     echo $e->getMessage(); 

}

die(var_dump($response));
$clientV = new SoapClient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array('trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));

$params = new stdClass();
$params->Token = '';
$params->Period = 1;
$params->VehicleType = '';
$params->Vin = '5YFBURHE3FP331896';
$params->Region = 1;
$params->Mileage = 100;

$result = $clientV->getDefaultVehicleAndValueByVin(array('vehicleRequest' => $params));