PHP Soap Server:使用字符串(xml 字符串)而不是 WSDL 文件(指向它的 URL)实例化 [英] PHP Soap Server: instantiate with a string (xml string) instead of WSDL file (url to it)

查看:15
本文介绍了PHP Soap Server:使用字符串(xml 字符串)而不是 WSDL 文件(指向它的 URL)实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Soap Server 的 PHP 页面(我看过):

The PHP page of Soap Server (I've seen it):

http://www.php.net/manual/en/soapserver.肥皂服务器.php

但是对于我自己的问题,我缺少一个重要的文档:

But I'm missing an important lack of documentation there for my very own problem:

我需要知道是否可以像 SimpleXML 类那样直接使用 XML 字符串实例化服务器:

I need to know if it's possible to instantiate the Server directly with an XML string, like SimpleXML class does:

//From var (the one I want):
$movies = new SimpleXMLElement($xmlstr);

//From file and from string (the one I want):
$xml = simplexml_load_file('test.xml');

$xml = simplexml_load_string($string);

所以我想做这样的事情:

So I would like to do something like this:

$wsdl_cont = file_get_contents("../xmls/mywsdl.wsdl");
$server = new SoapServer($wsdl_cont);

有可能吗?

这样做的原因是,因为我有一些不同的 URL 必须使用相同的 XML,所以我需要对模板 URL 进行动态替换,并将其更改为正确的,然后加载WSDL.但我不想将立即生成的 WSDL 保存在 HDD 上,以便在读取后立即将其删除.

The reason for this is, because I have some different URLs which have to use the same XML, so I need to do a replace on the fly on a template URL, and change it to the right one and then, load the WSDL. But I don't want to save on HDD the instantly generated WSDL to delete it right after having it read.

是否可以在 PHP 上创建某种虚拟文件"并像使用磁盘读取文件一样使用它?某种o流缓冲区?或者某种动态的文件描述符?

Is it possible to create some kind of "virtual file" on PHP and use it like if it was a disk read one? Some kind o stream buffer? Or some kind of file descriptor on the fly?

推荐答案

是的,可以通过创建一个 DATA URI 从文件内容中取出并将其用作文件".

Yes it's possible by creating a DATA URI out of the files content and use it as "file".

$name = 'mywsdl.wsdl';
$path = '/path-to-file/'.$name;
$data = file_get_contents($path);
$file = 'data://text/plain;base64,'.base64_encode($data);
$server = new SoapServer($file);

这应该可以满足您的要求.相关答案.

This should do what you're looking for. A related answer.

这篇关于PHP Soap Server:使用字符串(xml 字符串)而不是 WSDL 文件(指向它的 URL)实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆