2012-11-27 80 views
4

我正在嘗試在我的ZF2應用程序中創建一個SOAP服務器,該服務器可以使用嚮導導入Visual Studio並將其導入到C#應用程序中。我已經創建了該服務並使用soapUI進行了測試。我在soapUI中運行了WS-I一致性測試,並且我的服務通過了它。但是,當我嘗試使用Visual C#Express 2008將該服務添加到C#應用程序中時,它說HTML文檔沒有Web服務發現信息。Zend Framework 2與.NET不兼容的SOAP

這裏是代碼,我用我的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; 
    } 
} 

任何想法?

的SoapClass是好的,但在生成WSDL的時刻和:

回答

4

閱讀和重新閱讀一遍又一遍的幾個帖子和文檔我對這個發現,最後與去解決碰到後服務器我不得不做出一些改變:

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(); 
    } 
} 
+0

我沒你說的話,還是不能導入到Visual Studio!任何線索? – HPM

2

我認爲你需要指定運輸:

$style = array('style'=>'document', 'transport'=>'http://schemas.xmlsoap.org/soap/http'); 
$soapAutoDiscover->setBindingStyle($style); 

和標題應該是:

header('Content-type: application/soap+xml');