2017-04-13 53 views
1

我正在使用PHP SoapClient,並且遇到了獲取請求格式的問題,正如第三方希望的那樣。PHP SoapClient - 在錯誤的地方執行操作

他們希望這樣的:

POST /service.asmx HTTP/1.1 
Host: service.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <Order xmlns="http://someservice"> 
     <json>string</json> 
    </Order> 
    </soap12:Body> 
</soap12:Envelope> 

然而,最近我似乎可以得到它,使用SoapClient的,是這樣的:

POST /service.asmx HTTP/1.1 
Host: service.com 
Content-Type: application/soap+xml; charset=utf-8; action="http://someservice" 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <Order> 
     <json>string</json> 
    </Order> 
    </soap12:Body> 
</soap12:Envelope> 

請注意,在我的請求,行動是如何在http標頭中,並且其理想格式的動作位於Order標籤中。問題是,SoapClient是在生成該動作的地方生成的 - 它從WSDL獲取特定的URL,它甚至不在我的代碼中。

我該如何告訴SoapClient把它放在正確的位置?就我而言,試圖只包括什麼是必要的,這是基本的代碼:

$this->client = new SoapClient($this->wsdl, array(
       'soap_version' => SOAP_1_2, 
       'encoding' => 'UTF-8', 
       'stream_context' => stream_context_create($context), 
       'trace' => true, 
       'exceptions' => true, 
      ) 
     ); 
    $json = json_encode($request); 

    // Prepare the xml 
    $xml = array(); 
    $xml[] = new SoapVar($json, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema', 'json'); 

    $this->finalXML = new SoapVar($xml, SOAP_ENC_OBJECT, null, null, 'Order'); 
    $this->response = $this->client->CreateOrder($this->finalXML); 
+0

'$ context'是什麼?什麼是'$ request'?這與你在上面顯示的XML有什麼關係?我在代碼中的任何地方都看不到'http:// someservice'。 – miken32

+0

$ context與我的一個頭文件相關,對於這個問題並不重要。 $ request與json相關,隻影響到這一點,與XML無關。我所指的url是從他們的WSDL生成的,而不是我的代碼。 –

+0

好的,只是想弄清楚示例代碼如何與示例XML相關。 – miken32

回答

1

後敲我的頭幾天,我發現了這一點,並最終使我接受,哈克解決方案的工作:

Change SOAP request format

顯然,當你使用寫得不好的Soap API時,你可以做的事情並不多。