我一直在使用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和客户端脚本编写了php web服务.当我通过php客户端获取数据库记录时,unicode记录显示为?????????? ???? ????("问号").
server.php
<?php
//call library
require_once 'config.php';
include_once("nusoap/lib/nusoap.php");
$conn = new Dbconn(HOST, DB, USER, PASS);
//using soap_server to create server object
$server = new soap_server;
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = true;
//register a function that works on server
$server->configureWSDL('designationdivisionwsdl', 'urn:designationdivisionwsdl');
// Register the method to expose
//$server->register('getallbook', // method name
// array('name' => 'xsd:string'), // input parameters
// array('return' => 'xsd:string'), // output parameters
// 'urn:hellowsdl', // namespace
// 'urn:hellowsdl#hello', // soapaction
// 'rpc', // …Run Code Online (Sandbox Code Playgroud) 我是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) 我试图通过PHP和SoapClient简单地将RAW xml发送到web服务.问题是当我对XML进行编码时,它会改变XML中转换为关联数组的元素顺序.
// Initialize the Soap Client:
$this->_transactionServicesClient = new SoapClient($soapWSDLUrl);
Run Code Online (Sandbox Code Playgroud)
将以下XML作为字符串发送到我的SoapClient的最佳方式是什么或者是什么?
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.micros.com/pos/les/TransactionServices">
<SOAP-ENV:Body>
<ns1:PostTransaction>
<ns1:REQ>
<ns1:RequestHeader>
<ns1:InterfaceVersion>3.0.7</ns1:InterfaceVersion>
<ns1:ClientName>TRANS_SERVICES</ns1:ClientName>
</ns1:RequestHeader>
<ns1:CheckDetailEntries>
<ns1:MenuItem>
<ns1:ReferenceEntry>Pizza4</ns1:ReferenceEntry>
<ns1:Count>1</ns1:Count>
<ns1:Price>10.00</ns1:Price>
<ns1:ItemNumber>112001</ns1:ItemNumber>
<ns1:PriceLevel>1</ns1:PriceLevel>
<ns1:Seat xsi:nil="true"/>
</ns1:MenuItem>
</ns1:CheckDetailEntries>
<ns1:CheckHeaderRequest>
<ns1:CheckId>03:21:05.050505</ns1:CheckId>
<ns1:GuestCount>1</ns1:GuestCount>
<ns1:GuestInformation>
<ns1:ID>001</ns1:ID>
<ns1:FirstName>xxx</ns1:FirstName>
<ns1:LastName>xxx</ns1:LastName>
<ns1:Address1>xxx Rd</ns1:Address1>
<ns1:Address2>xx</ns1:Address2>
<ns1:Address3>xx</ns1:Address3>
<ns1:PhoneNum>xx</ns1:PhoneNum>
<ns1:UserText1>None</ns1:UserText1>
<ns1:UserText2>None</ns1:UserText2>
<ns1:UserText3>None</ns1:UserText3>
<ns1:GUID></ns1:GUID></ns1:GuestInformation>
</ns1:CheckHeaderRequest>
<ns1:OrderTypeNumber>1</ns1:OrderTypeNumber>
</ns1:REQ>
</ns1:PostTransaction>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
更新/解决方案:这是我用来扩展SOAP客户端并发送原始Soap Envelope的代码:我的答案如下
实际上,问题不在于如何做,而是如果这是一个设计错误.我很担心,因为我已经阅读了很多关于在WS中仅使用标准数据类型的内容.但是,我实现一个接收HashMap并使用nuSoap从PHP填充该参数没有问题.
我有一个带有这个成员的ParameterBean类(当然还有getter和setter),其中包含一个HashMap.
private int ID;
private String value;
private String name;
private HashMap<Integer, String> map = new HashMap<Integer, String>();
Run Code Online (Sandbox Code Playgroud)
以及从此类接收实例的服务.然后从PHP客户端我调用:
$map = array(1 => 'Foo', 2 => 'Bar');
$paramsp = array(
'ID' => '1',
'value' => 'Some Value',
'name' => 'A Name',
'map' => $map
);
$params = array($paramsp);
$resp = $client->call('test',$params);
print_r($client->response);
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力!问题是:这不赞成吗?这会在某种程度上导致未来的头痛吗?
我是golang和Soap的新手,在解析soap msg方面遇到了麻烦.
我有肥皂消息
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<activationPack_completeResponse"http://tempuri.org/">
<activationPack_completeResult xsi:type="xsd:string">Active</activationPack_completeResult>
</activationPack_completeResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
现在我应该如何在golang中解组它们应该是标签Soap Envelope的结构声明.
我有一些结构如下:
type MyRespEnvelope struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Soap *Body
}
type Body struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
GetResponse *ActivationPack_CompleteResponse
}
type ActivationPack_CompleteResponse struct {
XMLName xml.Name `xml:"activationPack_completeResponse"`
Id string `xml:"xmlns,attr"`
MyVar string `xml:"activationPack_completeResult"`
}
Run Code Online (Sandbox Code Playgroud)
但我收到的错误如下:
error: expected element <Envelope> in name space http://schemas.xmlsoap.org/soap/envelope/ but have soap*stopped,reason="end-stepping-range",frame={addr="0x0000000000401211",func="main.UnmarshalFirstDitto",args=[{name="data",value="\"\\nNotice: Undefined variable: area in /var/www/nusoap/dittotv.php on line 25\\n\\nNotice: Undefined variable: …Run Code Online (Sandbox Code Playgroud) 我需要从客户端接收这样的 XML 输入(包含 2 个或更多元素):
<list>
<item>
<code xsi:type="xsd:string">123</code>
<product xsi:type="xsd:string">hello</product>
<level xsi:type="xsd:float">3</level>
</item>
<item>
<code xsi:type="xsd:string">1234</code>
<product xsi:type="xsd:string">hello2</product>
<level xsi:type="xsd:float">4</level>
</item>
</list>
Run Code Online (Sandbox Code Playgroud)
我可以定义一个像这样的复杂类型来描述服务方法的输入参数(使用数组(数组(...)?
$server->wsdl->addComplexType(
'姓名',
'复杂类型',
'结构',
'全部',
'',
数组(数组(
'代码' => 数组('名称' => '代码', '类型' => 'xsd:string'),
'产品' => 数组('名称' => '产品', '类型' => 'xsd:string'),
'level' => array('name' => 'level', 'type' => 'xsd:float')
))
);
$server->register('updateCode', // 方法名称
array('name' => 'tns:name'), // 输入参数
array('return' => 'xsd:string'), // 输出参数
'urn:updateCode', // 命名空间
'urn:updatecode#updateCode', //soapaction
'rpc', // 样式
'编码' // … 我在将数组传递给我使用 php 和 nusoap 创建的 Web 服务函数时遇到问题。问题是我想我做错了什么..我怀疑问题出在函数或我的客户端。当我发送一个数组时,它不会进入我在 Web 服务中注册的函数。当我调用网络服务时,我只得到空数组的响应。我希望有人能在这里帮助我。谢谢。
编辑:我设法修复它。我忘了为请求构建一个结构。
服务器端:
<?php
//include nusoap
require_once('c:\\wamp\\www\\nusoap.php');
//create server instance
$server = new soap_server();
//configure wsdl
$server->wsdl->schemaTargetNamespaces = 'urn:GetArr';
$server->configureWSDL('GetArr','urn:GetArr');
$server->wsdl->addComplexType(
'Product',
'complexType',
'struct',
'all',
'',
array(
'name' => array('name' => 'name', 'type' => 'xsd:string'),
'code' => array('name' => 'code', 'type' => 'xsd:string'),
'price' => array ('name' => 'price', 'type' => 'xsd:int'),
'quantity' => array ('name' => 'quantity', 'type' => 'xsd:int'),
'total_price' => array('name' => 'total_price', 'type' => 'xsd:int')
));
//this …Run Code Online (Sandbox Code Playgroud)