2014-12-31 4 views
0

SOAP과 XML을 처음 사용합니다. 몇 가지 자습서를 거쳤지만 아무 것도 나를 위해 일하는 것 같습니다. 아래 코드는 지금까지 작성했지만 여전히 원하는 결과를 얻을 수 없습니다.SOAP 요청하기

$soapclient = new SoapClient('http://www.carrierrate.com/RateQuoteService/service.asmx?WSDL'); 
$params = array('quoteInfo' => '', 'quoteItems' => ''); 
$response = $soapclient->RateMyShipment($params); 
var_dump($response); 

실제로 배송료를 찾으려고합니다. "사용자 자격 증명이 유효하지 않습니다"라고 표시됩니다. 내가

$params = array('ShipperUserNameWithCarrierRate' => 'myUsername', 'ShipperPasswordWithCarrierRate' => 'myPassword'); 

으로 사용자 자격 증명을 전달할 수 있습니다하지만 난 ShipmentRequestDate, ShipmentOriginZip 포함 "QuoteInfo"의 전체 배열을 전달하는 방법을 받고 있지 않다 것처럼

제가 놓친 거지 알려이나 바랍니다 .. 보인다 여기에 언급 된 완전한 SOAP 요청을 보낼 수있는 쉬운 방법이 있습니까? http://www.carrierrate.com/RateQuoteService/service.asmx?op=RateMyShipment thorugh jQuery/Ajax

PHP 또는 jQuery와 함께 작업 할 수 있습니다.

귀하의 도움이 크게 도움이 될 것입니다.

+0

RateMyShipment()는 soap server에 정의 된 메소드입니다. 이 함수의 정의 자로부터 매개 변수의 형식과 형식을 알아야합니다. RateMyShipment –

+0

좀 더 설명해 주시겠습니까? 모든 값에 대해 quoteInfo와 quoteItems의 두 배열을 전달하고 응답을 위해 RateMyShipment 함수를 호출해야합니까? – AZee

+0

시험 사용자 이름과 암호를 제공 할 수 있습니까? 귀하의 사용자 이름과 암호를 제공하면 문제를 해결할 수 있습니다. 많은 비누 클라이언트와 서버를 개발할 수 있습니다. – phpniki

답변

2

기본적으로 quoteInfoquoteItems은 모두 자체적으로 배열이어야하므로 $params은 2 개의 배열로 구성된 배열이됩니다. 시도

$quoteInfo = array('ShipperUserNameWithCarrierRate' => 'myUsername', 
        'ShipperPasswordWithCarrierRate' => 'myPassword', 
        ...); 

다음

$params = array('quoteInfo' => $quoteInfo, 'quoteItems' => $quoteItems); 

각 배열에 사용할 수있는 키/값 쌍은 당신이 링크 된 SOAP의 XML의 desription에 정의되어

$quoteItem1 = array('ItemWeight' => ..., 
        'ItemHeight' => ..., 
        ...); 
$quoteItems = array('QuoteItemsInfo' => array($quoteItem1, ...)); 

.

+0

나는 이미 이것을 시도했으며 업데이트 된 코드는 http://pastebin.com/MpbSYEnU입니다. 빈 배열과 응답은 Null입니다. – AZee

+0

수 없습니다. '$ quoteItems = array ('QuoteItemsInfo'=> $ QuoteItemsInfo);'$ quoteItems = array ('QuoteItemsInfo'=> array ($ QuoteItemsInfo))를 제외하고, ;- 미안하지만 나는 더 이상 당신을 도울 수 있다고 생각하지 않는다 :-( – Digifaktur

+0

어쨌든 답장을 보내 주셔서 감사합니다 :) – AZee

0
$soapclient = new SoapClient('http://www.carrierrate.com/RateQuoteService/service.asmx?WSDL'); 

if ($soapclient) 
{ 
    $params = array ('quoteInfo' => 
      array (
        "ShipperUserNameWithCarrierRate" => "username", 
        "ShipperPasswordWithCarrierRate" => "password", 
        "ShipmentRequestDate"=> "2015-01-16", 
        "ShipmentOriginZip"=> "", 
        "ShipmentDestinationZip"=> "", 
        "ShipmentPickupService" => "None", 
        "ShipmentDropoffService" => "None", 
        "ShipmentExtraService"=> "None", 
        "IsTradeShow"=> "0", 
        "IsSortnSegregate" => "0", 
        "IsInsidePickup" => "0", 
        "IsExtremeLength"=> "0", 
        "ExtremeLength"=> "", 
        "ExtremeLengthBundleCount" => "", 
        "isInsuranceRequired" => "0", 
        "isNewItem" => "0", 
        "RequiredInsuranceAmount"=> "", 
        "NonCommercialDeliveryType"=> "None", 
        "IsProtectFromFreeze" => "0" 
      ), 'quoteItems' => 
      array (
        "FAKClass" => "", 
        "ItemWeight" => "1", 
        "ItemHeight" => "30", 
        "ItemLength" => "30", 
        "ItemWidth" => "20", 
        "PackageTypeName" => "", 
        "PackageTypeId" => "", 
        "ProductId" => "", 
        "ItemNmfc" => "", 
        "Hazardous" => "1", 
        "Pieces" => "", 
        "PieceDescription" => "", 
        "PalletCount" => "" 
    )); 

    $response = $soapclient->__soapCall("RateMyShipment", array ($params)); 
    var_dump($response); 
} 
+0

코드를 실행하면'SOAP-ERROR : 인코딩 : 객체에 'ShipmentRequestDate'속성이 없습니다. quoteInfo 배열을 다른 값으로 업데이트하면 응답 배열은 여전히 ​​비어 있습니다. – AZee

+0

예를 들어 ShipmentRequestDate 또는 ShipmentDestinationZip 및 ShipmentOriginZip과 같은 일부 매개 변수가 필요하므로 위와 같이 시도하고 출력을 확인하십시오. –

+0

네가 이전에 언급 한 예에서 이미 나머지 매개 변수를 전달했지만 응답 배열은 여전히 ​​비어 있습니다. ( – AZee

0

서비스 제공 업체 팀에 문의하셨습니까? 일부 필수 매개 변수가 누락 된 것일 수 있으므로 응답에 오류 코드가있는 객체를 요청할 때 문제가 발생하면 빈 응답이 표시됩니다. webservice를 작성한 사람들과 연결하십시오. 그들은 당신을 안내 할 올바른 사람입니다.

1

저는 기분이 좋아서 이에 대한 확실한 해결책을 제시 할 것입니다. 지금은 적어도 년 동안 CarrierRate API 덤비는되었고, 나는이 클래스를 사용하려면 그것을

http://pastie.org/10245578

에 대한 클래스를 작성 관리해야, 당신은 물론 당신의 스크립트를 요구해야하며, 실제로 중요한 누락 된 매개 변수를 추가하십시오.

require('quote.php'); 
$quoteInfo['ShipmentOriginZip'] = 28906; 
$quoteInfo['ShipmentDestinationZip'] = 30301; 
$quoteInfo['ShipmentRequestDate'] = date('Y-m-d', strtotime('+2 months')); 

$quoteItems['FAKClass'] = 55; 
$quoteItems['ItemWeight'] = 10000; 
$quoteItems['ItemHeight'] = 60; 
$quoteItems['ItemLength'] = 60; 
$quoteItems['ItemWidth'] = 60; 
$quoteItems['Pieces'] = 60; 
$quoteItems['PalletCount'] = 60; 

$carrierRate = new CarrierRate($quoteInfo, $quoteItems); 
$carrierRate->execQuote(); 

if($carrierRate->hasError == false) { 
    echo "<h2>Business to Business Quotes</h2>"; 
    echo "<ul>"; 
    foreach($carrierRate->quote_responses['b'] as $k=>$q) { 
     echo "<li>" . $q['carrierName'] . " @ " . $q['after_price'] . "</li>\n"; 
    } 
    echo "</ul>"; 

    echo "<h2>Business to Residential Quotes</h2>"; 
    echo "<ul>"; 
    foreach($carrierRate->quote_responses['r'] as $k=>$q) { 
     echo "<li>" . $q['carrierName'] . " @ " . $q['after_price'] . "</li>\n"; 
    } 
    echo "</ul>"; 
} else { 
    echo "<pre>", print_r($carrierRate->errors), "</pre>"; 

}