2009-06-03 39 views
4

當消耗.NET WCF web服務我得到以下響應(錯誤):NuSOAP:如何更改內容類型的請求?

不受支持的HTTP響應狀態415 無法處理該消息,因爲該內容類型「文本/ XML; charset = UTF-8' 不是預期的類型'application/soap + xml;字符集= UTF-8' 。

如何更改內容類型?我無法在NuSOAP論壇/文檔中找到它,或者我可能忽略了一些東西......

回答

9

我知道這是一箇舊的帖子,但我跑到這個頁面尋找答案。

application/soap+xml是內容類型使用SOAP 1.2, text/xml是使用SOAP 1.1的時候過去了,

這樣的事情應該做的伎倆,

$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1)); 
0

我被困在這個上面了。

的祕密是在web.config 變化的wsHttpBinding到basicHttpBinding的

像這樣:

<endpoint address="" binding="basicHttpBinding" contract="YourProject.View.Whatever.IYourService"> 

希望幫助! /Erik

+0

我無法將其更改爲basicHttpBinding,因爲我們需要wsHttpBinding來獲取證書。 – jao 2009-06-05 09:30:24

2

它看起來像有一個輕微的疏忽在NuSOAP庫中......它假定內容頭必須是「text/xml」,所以如果你的客戶端試圖連接到一個輸出application/soap + xml頭的服務,你最終會得到如下錯誤:

不是text/xml類型的響應:application/soap + xml; charset = utf-8

要測試這一點,您可能會從以下小函數模式中受益,我用它來登錄到SOAP服務。請記住,打印客戶端對象!你可能實際上沒有看到結果!

require_once('path/to/downloaded/libraries/nusoap.php');  
var $endpoint = 'https://somedomain.com/path/to/soap/server/Login'; 
var $client; // the soapclient object 

function SOAP_Login() 
{ 
    $this->client = new soapclient($this->endpoint); 

    $err = $this->client->getError(); 
    if ($err) 
    { 
     // Display the error 
     echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>'; 
     exit; 
     // At this point, you know the call that follows will fail 
    } 

    $params = array( 
     'some' => 'thing.. depends on what the WSDL expects' 
    ); 

    $result = $this->client->call('someFunction', $params);  

    print_r($result); // Without the fix, this prints nothing (i.e. false) !!! 

    print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str 
} 

當我打印我的$結果,我什麼也沒得到,但是當我打印出來的$客戶端對象,我看到有錯誤。

小黑客,我實現了在nusoap.php文件,圍繞行7500尋找此if語句:

if (!strstr($headers['content-type'], 'text/xml')) { 
    $this->setError('Response not of type text/xml: ' . $headers['content-type']); 
    return false; 
} 

它改成這樣:

if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml')) { 
    $this->setError('Response not of type text/xml: ' . $headers['content-type']); 
    return false; 
} 

這一切它是否可以讓NuSOAP處理髮出「application/soap + xml」標題(這是一個有效的xml標題)的響應。

$client = new nusoap_client($params); 
$client->soap_defencoding = 'UTF-8'; 
3

您可以指定的NuSOAP的編碼與web服務一樣,流

$客戶端=新nusoap_client($ params)方法;

$ client-> soap_defencoding ='UTF-8';

被選爲正確的答案不適用於NUSOAP,因此不是適當的答案。

+0

哇這很容易。謝謝! – 2013-03-18 19:20:06

相關問題