あなたがあなたの答えを見つけたかどうかはわかりません。そのような問題に遭遇するかもしれない他の誰かのためだけに:
WSDLは、Webサービスが定義および記述される言語です。これは基本的に、サーバーによって提供されるすべての関数の入出力パラメーターを含むXMLファイルです。また、サービスを提供しているサーバー自体に関する情報も含まれています。
Webサービスを作成できるようにするには、提供したコードを使用する必要があります。これにより、実際にはSymfonyが「/path/to/hello.wsdl」上のクライアントにサービスを提供できるようになります(私の例では、このパスは/です。 YourDesiredPathFor / services.wsdl)、およびまた、上記の情報を正しいWSDL形式で含む有効なWSDLドキュメントを提供する必要があります。問題は、Symfony(またはこの問題についてはPHP自体)にはファイルを自動的に作成する手段がないことです。
この問題を解決するには、外部のWSDLジェネレーターを使用する必要があります。PHP-WSDL-Creatorを使用することをお勧めします。phpファイル内に記述されたアノテーションを使用してWSDLファイルを作成し、SoapServerも実行します。つまり、提供したコードも必要ありません。また、さまざまなプロトコルと言語のクライアントを提供する適切なインターフェイスとアドオンもあります。
ただし、少し調整する必要があります。symfonyの基準にしたければ、その一部を書き直す必要があると思います。ただし、外部ライブラリとして使用したい場合は、それも機能する可能性があります。私が行った方法は、抽出したファイルを./vendor/php_wsdl/lib/php_wsdl/srcにコピーすることでした(長い間、そうではありませんか?おそらくもっと簡単なパスでも機能します!); 次に、./ vendor / php_wsdl / lib/php_wsdlでphp_wsdl.phpを定義しました。
<?php
require_once __DIR__. '/src/class.phpwsdl.php';
class WSDL_PhpWsdl extends PhpWsdl{
}
次に、「。/ app / autoload.php」に次の行を追加して、Symfonyが作成された拡張機能を使用できるようにします。
require_once __DIR__. '/../vendor/php_wsdl/lib/php_wsdl/php_wsdl.php';
たったひとつ!拡張機能には、作成されたwsdlファイルとすべてをキャッシュするための「キャッシュ」フォルダーが必要です。残念ながら、プロジェクトを迅速に完了する必要があるため、キャッシュフォルダを適切に管理するための十分な時間がありません。私のやり方よりも間違いなく良い方法があります、そして私はそれらについて知って本当にうれしいです。
とにかく、今度は拡張機能の機能を使用する必要があります!そのために、使用していたバンドルの「ServerController」を作成しました。
<?php
namespace Tara\PageControllerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class ServiceController extends Controller
{
function wsdlAction(){
\PhpWsdlServers::$EnableRest = false;
$soap= \WSDL_PhpWsdl::CreateInstance(
null, // PhpWsdl will determine a good namespace
$this->generateUrl('service_wsdl', array(), true), // Change this to your SOAP endpoint URI (or keep it NULL and PhpWsdl will determine it)
__DIR__. '/cache', // Change this to a folder with write access
Array( // All files with WSDL definitions in comments
dirname(__FILE__). '/../Services/MyService.php'
),
null, // The name of the class that serves the webservice will be determined by PhpWsdl
null, // This demo contains all method definitions in comments
null, // This demo contains all complex types in comments
false, // Don't send WSDL right now
false // Don't start the SOAP server right now
);
if($soap->IsWsdlRequested()) // WSDL requested by the client?
$soap->Optimize=false; // Don't optimize WSDL to send it human readable to the browser
$soap->RunServer();
}
}
ご覧のとおり、キャッシュフォルダへのパスはローカルディレクトリにあります。つまり、手動で./src/Tara/PageControllerBundle/Controllerに作成する必要があります(私の場合は明らかに、パスを変更する必要があります)。 。キャッシュフォルダを管理するためのより良い方法があると確信しています。そこに線があります:
dirname(__FILE__). '/../Services/MyService.php
この行は、WSDLページを作成するためにアノテーションを探す場所を拡張機能に指示します。また、「service_wsdl」へのルートを定義する必要があります。
service_wsdl:
pattern: /YourDesiredPathFor/services.wsdl
defaults: {_controller: TaraPageControllerBundle:Service:wsdl}
ご覧のとおり、コントローラーはServiceControllerであり、それを担当する関数はwsdlActionです。定義された正確な関数!
例として、私は自分のMyService.phpを提供します。
<?php
namespace Tara\PageControllerBundle\Services;
use Tara\PageControllerBundle\Model\...
/**
* @service Tara\PageControllerBundle\Services\MyService
*/
class MyService
{
/**
* Function Create
*
* @param string $link
* @param string $title
* @param string $image
* @param string $description
* @return boolean Status of the creation
* @pw_rest POST /YourDesiredPathForAction/create Create The Object
*
*/
public function Create($link, $title, $image, $description)
{
// your code that handles the data goes here. this is not a part of the annotations!
return (bool)$result;
}
}
これで、SoapClientを使用して次のWebサービスに接続できるようになる可能性があります。
http://your-server.something/YourDesiredPathFor/services.wsdl?wsdl
作成関数を呼び出します!上記のアドレスを開くことで、拡張子の出力を確認することもできます。拡張機能は、「人間が読める」バージョンも提供します。
http://your-server.something/YourDesiredPathFor/services.wsdl。
これが誰かの助けになったのかどうか知りたいです!:)