我想使用nuSOAP v 1.114在PHP Web服务中返回一个文章对象数组.这就是我设置WSDL的方式:
$server->wsdl->addComplexType(
'ArticleType',
'complexType',
'struct',
'all',
'',
array('articleId' => array('name'=>'articleId', 'type'=>'xsd:int'),
'heading' => array('name'=>'heading', 'type'=>'xsd:string'),
'text' => array('name'=>'text', 'type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'ArrayOfArticleType',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:ArticleType[]' // ArticleType[]
)
),
'tns:ArticleType'
);
Run Code Online (Sandbox Code Playgroud)
我的PHP文章类非常简单:
class Article {
public $articleId;
public $heading;
public $text;
public function __construct($articleId, $heading, $text=NULL) {
$this->articleId = $articleId;
$this->heading = $heading;
$this->text = $text;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我只返回一个新的文章对象,如下所示:
function TestArrayReturn() {
$arr = new Article(12345, "Test …Run Code Online (Sandbox Code Playgroud) 我创建了一个函数来调用Web服务来获取pdf文件的内容.网络服务很好用.
我想当文件太大时会出现问题.
我可以在另一个有相同错误的服务器上修复同样的问题抛出memory_limit并且他的php版本是5.4.Nusoap版本是0.9.5,我通过作曲家的捆绑使用它.
这个包来自https://packagist.org/packages/econea/nusoap我正在使用v0.9.6.
在我无法修复错误的服务器中,我使用的是php 7.0.Nusoap版本在此服务器中也是0.9.5.
/**
* @param string $docId
* @return string
*/
public function getDocumentFromDocId(string $docId)
{
$client = new \nusoap_client('http://'.$this->ip.'/arcdoc/WebServiceServer.php?wsdl', true);
$response = $client->call('GetDoc', array(
'xxxx1' => 'xxxxxx',
'xxxx2' => base64_encode('xxxxx'),
'xxxx3' => base64_encode("yyyyyyy"),
'xxxx4' => base64_encode($docId)
));
var_dump($response);
return $response;
}
Run Code Online (Sandbox Code Playgroud)
当我var_dump()的内容回复此回复时:
/var/www/html/project/src/AppBundle/Service/whatever.php:55:boolean false
Run Code Online (Sandbox Code Playgroud)
如果文件大于6-8M则为false $response但是如果文件小于6-8M则不成问题.
所以,我可以说webservice在大小小于6-8M的文件中运行良好.
知道为什么我没有得到答案吗?
我正在测试将相同的pdf从中减少9M到6M并且效果很好,因此它必须与文件的大小有关.在我的情况下似乎开始工作不好7-9M.
我正在为PHP应用程序实现Web服务,并试图了解标准Web服务和RESTful Web服务所提供的内容.我的目的是编写包装器代码来抽象出Web服务的详细信息,以便开发人员可以"实例化远程对象"并使用它们.以下是我的想法,或许你们中的一些人可以添加你的经验并扩展这个:
RESTful Web服务
基本上只是"按需提供XML源",因此您可以为客户端应用程序编写包装器代码,以便它可以通过以下方式查询服务器应用程序:
$users = Users::getUsers("state = 'CO'");
Run Code Online (Sandbox Code Playgroud)
RESTful Web服务通常只能从客户端的视图中读取,尽管您可以编写可以使用POST或GET在服务器上进行更改的代码,例如传递加密令牌以确保安全性,例如:
$ users = Users :: addUser($ encryptedTrustToken,'jim',$ encryptedPassword,'James','Taylor');
这将在服务器应用程序上创建一个新用户.
标准Web服务
标准Web服务最终基本上做同样的事情.他们的一个优势是客户可以通过WSDL发现他们的细节.但除此之外,如果我想编写允许开发人员远程实例化,编辑和保存对象的包装代码,我仍然需要实现包装器代码.SOAP不会为我做任何事情,它可以做到这一点:
$soap = new nusoap_client('http://localhost/test/webservice_user.php?wsdl', true);
$user = $soap->getProxy();
$lastName = $user->lastName();
Run Code Online (Sandbox Code Playgroud)
但如果我想编辑并保存:
$user->setLastName('Jones');
$user->save();
Run Code Online (Sandbox Code Playgroud)
然后我需要例如处理服务器端的所有状态,SOAP似乎并不在每个客户端的服务器端保存该对象.
也许我正在使用的PHP SOAP实现存在限制(nusoap).也许Java和.NET实现可以做得更多.
将享受听取您的反馈意见,以清理其中的一些云.
无法弄清楚如何使NuSOAP使用UTF-8作为内容类型.它不断吐出"ISO-8859-1".这是我尝试的相关代码位:
$soapclient=new soapclient($url1,'wsdl');
$soapclient->http_encoding='utf-8';
$soapclient->defencoding='utf-8';
if($soapclient->fault){
$retdata=$soapclient->fault;
}else{
if($soapclient->getError()){
$retdata=$soapclient->getError();
}else{
$params=array($xmldata);
$retdata=$soapclient->call($doit,$params,$url1,$url2);
}
}
Run Code Online (Sandbox Code Playgroud)
这是请求:
POST xxxxxxxxxxxx HTTP/1.0
Host: xxxxxxxxxxxxx
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "xxxxxxxxxxxxxxxxx"
Content-Length: 1629
Run Code Online (Sandbox Code Playgroud)
我甚至进入了nusoap.php并更改了几行ISO硬编码的行.我错过了什么?
我正在将使用NuSoap的旧代码转换为PHP Soap Library.但是在PHP Soap Libary中,NuSoap PHP中的方法getError似乎不存在,我收到此错误:
Fatal error: Uncaught SoapFault exception:
[Client] Function ("getError") is not a valid method for this service in index.php:33
Stack trace: #0 index.php(33): SoapClient->__call('getError', Array) #1 index.php(33):
SoapClient->getError() #2 index.php(63): pay() #3 {main} thrown in /homeindex.php on line 33
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<?php
$client = new SoapClient('my soap server');
$err = $client->getError();
?>
Run Code Online (Sandbox Code Playgroud)
我应该如何在PHP Soap库中获得错误?
我一直在使用PHP4的脚本,它依赖于NuSOAP.现在,我正在尝试将其移至PHP5,并在那里使用对SOAP的buildin支持.
$wsdlPath = ""; // I have obviously set these variables to something meaningful, just hidden for the sake of security
$apiPath = "";
$username = "";
$password = "";
// PHP5 style
$client = new soapclient($wsdlPath, array('login'=>username,
'password'=> $password,
'soap_version'=> SOAP_1_2,
'location'=> $apiPath,
'trace'=> 1));
// PHP4/NuSOAP style
$client = new soapclient($wsdlPath, true);
client->setEndpoint($apiPath);
$client->setCredentials($username, $password);
$client ->loadWSD);
Run Code Online (Sandbox Code Playgroud)
PHP5版本抛出以下异常堆栈跟踪:
EXCEPTION=SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://external-nbb.napi.norwegian.no.stage.osl.basefarm.net/api/napi1300?wsdl' in /home/eisebfog/public_html/database/norwegian.php:31
Stack trace:
#0 /home/eisebfog/public_html/database/norwegian.php(31): SoapClient->SoapClient('http://external...', Array)
#1 /home/eisebfog/public_html/database/index.php(53): …Run Code Online (Sandbox Code Playgroud) 我想在我的Web服务中返回一个字符串数组
我试过了:
<?php
require_once('nusoap/nusoap.php');
$server = new soap_server();
$server->configureWSDL('NewsService', 'urn:NewsService');
$server->register('GetAllNews',
array(),
array('return' => 'xsd:string[]'),
'urn:NewsService',
'urn:NewsService#GetAllNews',
'rpc',
'literal',
''
);
// Define the method as a PHP function
function GetAllNews()
{
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
return $stack;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.这个的正确语法是什么?
在此先感谢您的帮助
我需要以纯文本用户名和密码的形式连接到需要身份验证凭据的Web服务.
我对SOAP有基本的了解,并且设法使用NuSOAP连接到不需要用户名或密码的其他开放Web服务.
以下内容发送给我:
<?php
// Set up security options
$security_options = array("useUsernameToken" => TRUE);
$policy = new WSPolicy(array("security" => $security_options));
$security_token = new WSSecurityToken(array(
"user" => "xxx",
"password" => "xxx",
"passwordType" => "basic"));
// Create client with options
$client = new WSClient(array("wsdl" => "https://xxx.asmx?wsdl",
"action" => "http://xxx",
"to" => "https://xxx",
"useWSA" => 'submission',
"CACert" => "cert.pem",
"useSOAP" => 1.1,
"policy" => $policy,
"securityToken" => $security_token));
// Send request and capture response
$proxy = $client->getProxy();
$input_array = array("From" => "2010-01-01 00:00:00", …Run Code Online (Sandbox Code Playgroud) 对不起我的英语不好 :)
我有 NuSOAP 0.9.5 版。我在尝试获取大数据时遇到了 php 错误:
PHP 致命错误:允许的内存大小为 134217728 字节已用尽(尝试分配 27255652 字节)
堆栈跟踪显示问题出在 varDump 方法中。
我的解决办法是:
我已将 varDump 方法(在 nusoap.php 中)更改为:
function varDump($data) {
$ret_val = "";
if ($this->debugLevel > 0) {
ob_start();
var_dump($data);
$ret_val = ob_get_contents();
ob_end_clean();
}
return $ret_val;
}
Run Code Online (Sandbox Code Playgroud)
然后重置
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']
Run Code Online (Sandbox Code Playgroud)
到 0(从 9)。在 class.nusoap_base.php 和 nusoap.php 中。
这对我有帮助。
有没有人对此有任何评论?或者也许更好的解决方案?
我是nusoap和Web服务的新手.
wsdl文件来自客户端.我有一个基本的Web服务使用默认URL,它通过Web地址提供wsdl:http://hiddenurl.com/ws/schema/Terminal.wsdl
但客户端的文档说:"请在本地下载WSDL和XML模式文件,以便您的代码使用.不要每次都从我们的服务器获取这些文件."
所以我一直在尝试在本地托管wsdl文件,或者通过我自己的Web服务器,但都没有工作.
我试过了:
$wsdlUrl = 'http://supplied-url.com/schema/Terminal.wsdl' // working but discouraged
$wsdlUrl = 'http://my-own-IIS-based-url/schema/Terminal.wsdl' // url loads and I can
// view wsdl file, but when I load run webservice is returns blank / nothing
$wsdlUrl = 'path/to/local/Terminal.wsdl' // returns blank or 'boolean'false'
$tempUrl = realpath('path/to/local/Terminal.wsdl') // get absolute url
wsdlUrl = tempUrl; // returns blank screen or 'boolean'false'
Run Code Online (Sandbox Code Playgroud)
有什么方法可以让Web服务使用来自客户端最初提供的位置以外的位置的wsdl文件?我看到一些Web服务器的引用返回wsdl与http://getfile.php?file.wsdl,但我不明白'getfile.php'中的内容是为了通过以下方式传递wsdl请求参数.
这是我调用Web服务的PHP代码.同样,它适用于wsdl文件的客户端提供的URL,但是当我尝试以任何其他方式访问wsdl文件时,它不起作用.
<?php
require_once('nusoap.php');
$URI = 'http://api.hiddenurl.com/ws/schema';
$env = 'api';
$wsdlUrl = 'http://'.$env.'.hiddenurl.com/schema/Terminal.wsdl';
$licenseKey = 'xxxx-xxxx-xxxx-xxxx-xxxx';
$userName …Run Code Online (Sandbox Code Playgroud)