[英]Zend Framework 2 SOAP not compatible with .NET
我正在嘗試在ZF2應用程序中創建一個SOAP服務器,可以使用向導將它與Visual Studio一起導入到C#應用程序中。 我已經創建了服務並使用soapUI對其進行了測試。 我在soapUI中運行了WS-I一致性測試,並且我的服務通過了該測試。 但是,當我嘗試使用Visual C#Express 2008將服務添加到C#應用程序時,它表示HTML文檔沒有Web服務發現信息。
這是我在ZF2控制器中使用的代碼:
public function exampleAction() {
if (isset($_GET['wsdl'])) {
$soapAutoDiscover = new AutoDiscover();
$soapAutoDiscover->setBindingStyle(array('style' => 'document'));
$soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
$soapAutoDiscover->setClass('SoapClass');
$soapAutoDiscover->setUri($serverUrl);
echo $soapAutoDiscover->generate()->toXml();
} else {
$soap = new Server($serverUrl . '?wsdl');
$soap->setClass('SoapClass');
$soap->handle();
}
}
這是SoapClass類:
class SoapClass{
/**
* returns the sum of two parameters
* @param int $a
* @param int $b
* @return int
*/
public function sum ($a, $b){
return $a + $b;
}
/**
* twice function doc
* @param int $a
* @return int
*/
public function twice($a){
return $a * 2;
}
}
有任何想法嗎?
一遍又一遍地閱讀和重新閱讀后,我發現了一些帖子和文檔,最終得到了de解決方案:
SoapClass很好,但是在生成wsdl和服務器時,我必須進行一些更改:
public function exampleAction() {
if (isset($_GET['wsdl'])) {
//this is new:
$soapAutoDiscover = new AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
$soapAutoDiscover->setBindingStyle(array('style' => 'document'));
$soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
$soapAutoDiscover->setClass('SoapClass');
$soapAutoDiscover->setUri($serverUrl);
//so this is:
header("Content-Type: text/xml");
echo $soapAutoDiscover->generate()->toXml();
} else {
$soap = new Server($serverUrl . '?wsdl');
//drop this:
//$soap->setClass('SoapClass');
//and instead, add this:
$soap->setObject(new DocumentLiteralWrapper(new SoapClass()));
$soap->handle();
}
}
我認為您需要指定運輸方式:
$style = array('style'=>'document', 'transport'=>'http://schemas.xmlsoap.org/soap/http');
$soapAutoDiscover->setBindingStyle($style);
標頭應為:
header('Content-type: application/soap+xml');
在這里,您可以閱讀有關ZF SOAP組件兼容性的幾個問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.