I'm used to writing PHP code, but do not often use Object-Oriented coding. I now need to interact with SOAP (as a client) and am not able to get the syntax right. I've got a WSDL file which allows me to properly set up a new connection using the SoapClient class. However, I'm unable to actually make the right call and get data returned. I need to send the following (simplified) data:
我习惯了编写PHP代码,但不经常使用面向对象的代码。现在我需要与SOAP(作为客户机)进行交互,并且不能正确地获得语法。我有一个WSDL文件,它允许我使用SoapClient类正确地设置一个新的连接。但是,我不能真正做出正确的调用并返回数据。我需要发送以下(简化)数据:
- Contact ID
- 联系人ID
- Contact Name
- 联系人姓名
- General Description
- 一般的描述
- Amount
- 量
There are two functions defined in the WSDL document, but I only need one ("FirstFunction" below). Here is the script I run to get information on the available functions and types:
WSDL文档中定义了两个函数,但是我只需要一个(“FirstFunction”在下面)。下面是我用来获取可用功能和类型信息的脚本:
$client = new SoapClient("http://example.com/webservices?wsdl");
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
And here is the output it generates:
这是它产生的输出:
array(
[0] => "FirstFunction Function1(FirstFunction $parameters)",
[1] => "SecondFunction Function2(SecondFunction $parameters)",
);
array(
[0] => struct Contact {
id id;
name name;
}
[1] => string "string description"
[2] => string "int amount"
}
Say I want to make a call to the FirstFunction with the data:
假设我想用数据调用FirstFunction:
- Contact ID: 100
- 联系人ID:100
- Contact Name: John
- 联系人姓名:约翰
- General Description: Barrel of Oil
- 一般描述:油桶
- Amount: 500
- 数量:500
What would be the right syntax? I've been trying all sorts of options but it appears the soap structure is quite flexible so there are very many ways of doing this. Couldn't figure it out from the manual either...
正确的语法是什么?我已经尝试了各种选项,但是看起来soap结构非常灵活,所以有很多方法可以实现这一点。也无法从手册中找出答案……
UPDATE 1: tried sample from MMK:
更新1:MMK试用版:
$client = new SoapClient("http://example.com/webservices?wsdl");
$params = array(
"id" => 100,
"name" => "John",
"description" => "Barrel of Oil",
"amount" => 500,
);
$response = $client->__soapCall("Function1", array($params));
But I get this response: Object has no 'Contact' property
. As you can see in the output of getTypes()
, there is a struct
called Contact
, so I guess I somehow need to make clear my parameters include the Contact data, but the question is: how?
但我得到的响应是:对象没有“Contact”属性。正如您在getTypes()的输出中看到的,有一个名为Contact的结构体,因此我想我需要以某种方式表明我的参数包括联系人数据,但问题是:如何?
UPDATE 2: I've also tried these structures, same error.
更新2:我也尝试过这些结构,同样的错误。
$params = array(
array(
"id" => 100,
"name" => "John",
),
"Barrel of Oil",
500,
);
As well as:
以及:
$params = array(
"Contact" => array(
"id" => 100,
"name" => "John",
),
"description" => "Barrel of Oil",
"amount" => 500,
);
Error in both cases: Object has no 'Contact' property`
两种情况下的错误:对象没有“Contact”属性
10 个解决方案
#1
143
This is what you need to do.
Just to know, I tried to recreate your situation...
只是想知道,我试着重现你的处境……
- For this example, I made a .NET sample webservice with a
WebMethod
calledFunction1
and these are the parameters: - 在这个示例中,我使用名为Function1的WebMethod制作了.NET示例webservice,这些参数是:
Function1(Contact Contact, string description, int amount)
Function1(联系人,字符串描述,int数量)
-
In which
Contact
is just a beanclass
that has getters and setters forid
andname
like in your case.在这种情况下,Contact只是一个bean类,它具有id和名称的getter和setter。
-
You can download this .NET sample webservice at:
你可以下载这个。net样例webservice:
https://www.dropbox.com/s/6pz1w94a52o5xah/11593623.zip
https://www.dropbox.com/s/6pz1w94a52o5xah/11593623.zip
The code.
This is what you need to do at PHP side:
这是在PHP方面需要做的:
(Tested and working)
(测试和工作)
<?php
/* Create a class for your webservice structure, in this case: Contact */
class Contact {
function Contact($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://localhost:10139/Service1.asmx?wsdl");
/* Fill your Contact Object */
$contact = new Contact(100, "John");
/* Set your parameters for the request */
$params = array(
"Contact" => $contact,
"description" => "Barrel of Oil",
"amount" => 500,
);
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("Function1", array($params));
/* Print webservice response */
var_dump($response);
?>
How I know this is working?
- If you do
print_r($params);
you will see this output, as your webservice expects: - 如果你print_r(params);您将看到这个输出,正如您的web服务所期望的:
Array ( [Contact] => Contact Object ( [id] => 100 [name] => John ) [description] => Barrel of Oil [amount] => 500 )
数组([Contact]] => Contact Object ([id] => 100 [name] => John) [description] => Barrel of Oil [amount] => 500)
- When I debugged the sample .NET webservice I got this:
- 当我调试。net web服务示例时,我得到了以下信息:
(As you can see, Contact
object is not null and also other parameters, that means your request was successfully done from PHP side).
(如您所见,Contact对象不是null和其他参数,这意味着您的请求已从PHP端成功完成)。
- The response from .NET sample webservice was the expected one and shown at PHP side:
- .NET示例webservice的响应是预期的,在PHP端显示:
object(stdClass)[3] public 'Function1Result' => string 'Detailed information of your request! id: 100, name: John, description: Barrel of Oil, amount: 500' (length=98)
对象(stdClass)[3] public 'Function1Result' => string '详细信息您的请求!身份证号:100,姓名:John,描述:油桶,金额:500'(长度=98)
Hope this helps :-)
希望这有助于:-)
#2
57
You can use SOAP services this way too:
您也可以使用SOAP服务:
<?php
//Create the client object
$soapclient = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('CountryName' => 'Spain', 'CityName' => 'Alicante');
$response = $soapclient->getWeather($params);
var_dump($response);
// Get the Cities By Country
$param = array('CountryName' => 'Spain');
$response = $soapclient->getCitiesByCountry($param);
var_dump($response);
This is an example with a real service, and it works.
这是一个实际服务的示例,它是有效的。
Hope this helps.
希望这个有帮助。
#3
26
First initialize webservices:
首先初始化web服务:
$client = new SoapClient("http://example.com/webservices?wsdl");
Then set and pass the parameters:
然后设置并传递参数:
$params = array (
"arg0" => $contactid,
"arg1" => $desc,
"arg2" => $contactname
);
$response = $client->__soapCall('methodname', array($params));
Note that the method name is available in WSDL as operation name, e.g.:
注意,方法名在WSDL中作为操作名可用,例如:
<operation name="methodname">
#4
18
I don't know why my web service has the same structure with you but it doesn't need Class for parameter, just is array.
我不知道为什么我的web服务和你有相同的结构,但它不需要类参数,只是数组。
For example: - My WSDL:
例如:-我的WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://www.kiala.com/schemas/psws/1.0">
<soapenv:Header/>
<soapenv:Body>
<ns:createOrder reference="260778">
<identification>
<sender>5390a7006cee11e0ae3e0800200c9a66</sender>
<hash>831f8c1ad25e1dc89cf2d8f23d2af...fa85155f5c67627</hash>
<originator>VITS-STAELENS</originator>
</identification>
<delivery>
<from country="ES" node=””/>
<to country="ES" node="0299"/>
</delivery>
<parcel>
<description>Zoethout thee</description>
<weight>0.100</weight>
<orderNumber>10K24</orderNumber>
<orderDate>2012-12-31</orderDate>
</parcel>
<receiver>
<firstName>Gladys</firstName>
<surname>Roldan de Moras</surname>
<address>
<line1>Calle General Oraá 26</line1>
<line2>(4º izda)</line2>
<postalCode>28006</postalCode>
<city>Madrid</city>
<country>ES</country>
</address>
<email>gverbruggen@kiala.com</email>
<language>es</language>
</receiver>
</ns:createOrder>
</soapenv:Body>
</soapenv:Envelope>
I var_dump:
我var_dump:
var_dump($client->getFunctions());
var_dump($client->getTypes());
Here is result:
这里是结果:
array
0 => string 'OrderConfirmation createOrder(OrderRequest $createOrder)' (length=56)
array
0 => string 'struct OrderRequest {
Identification identification;
Delivery delivery;
Parcel parcel;
Receiver receiver;
string reference;
}' (length=130)
1 => string 'struct Identification {
string sender;
string hash;
string originator;
}' (length=75)
2 => string 'struct Delivery {
Node from;
Node to;
}' (length=41)
3 => string 'struct Node {
string country;
string node;
}' (length=46)
4 => string 'struct Parcel {
string description;
decimal weight;
string orderNumber;
date orderDate;
}' (length=93)
5 => string 'struct Receiver {
string firstName;
string surname;
Address address;
string email;
string language;
}' (length=106)
6 => string 'struct Address {
string line1;
string line2;
string postalCode;
string city;
string country;
}' (length=99)
7 => string 'struct OrderConfirmation {
string trackingNumber;
string reference;
}' (length=71)
8 => string 'struct OrderServiceException {
string code;
OrderServiceException faultInfo;
string message;
}' (length=97)
So in my code:
所以在我的代码:
$client = new SoapClient('http://packandship-ws.kiala.com/psws/order?wsdl');
$params = array(
'reference' => $orderId,
'identification' => array(
'sender' => param('kiala', 'sender_id'),
'hash' => hash('sha512', $orderId . param('kiala', 'sender_id') . param('kiala', 'password')),
'originator' => null,
),
'delivery' => array(
'from' => array(
'country' => 'es',
'node' => '',
),
'to' => array(
'country' => 'es',
'node' => '0299'
),
),
'parcel' => array(
'description' => 'Description',
'weight' => 0.200,
'orderNumber' => $orderId,
'orderDate' => date('Y-m-d')
),
'receiver' => array(
'firstName' => 'Customer First Name',
'surname' => 'Customer Sur Name',
'address' => array(
'line1' => 'Line 1 Adress',
'line2' => 'Line 2 Adress',
'postalCode' => 28006,
'city' => 'Madrid',
'country' => 'es',
),
'email' => 'test.ceres@yahoo.com',
'language' => 'es'
)
);
$result = $client->createOrder($params);
var_dump($result);
but it successfully!
但是它成功!
#5
2
First, use SoapUI to create your soap project from the wsdl. Try to send a request to play with the wsdl's operations. Observe how the xml request composes your data fields.
首先,使用SoapUI从wsdl创建soap项目。尝试发送一个请求来处理wsdl的操作。观察xml请求如何组成数据字段。
And then, if you are having problem getting SoapClient acts as you want, here is how I debug it. Set the option trace so that the function __getLastRequest() is available for use.
然后,如果您在获取SoapClient行为方面遇到了问题,我将通过以下方法进行调试。设置选项跟踪,使函数__getLastRequest()可用。
$soapClient = new SoapClient('http://yourwdsdlurl.com?wsdl', ['trace' => true]);
$params = ['user' => 'Hey', 'account' => '12345'];
$response = $soapClient->__soapCall('<operation>', $params);
$xml = $soapClient->__getLastRequest();
Then the $xml variable contains the xml that SoapClient compose for your request. Compare this xml with the one generated in the SoapUI.
然后$xml变量包含SoapClient为您的请求编写的xml。将此xml与SoapUI中生成的xml进行比较。
For me, SoapClient seems to ignore the keys of the associative array $params and interpret it as indexed array, causing wrong parameter data in the xml. That is, if I reorder the data in $params, the $response is completely different:
对我来说,SoapClient似乎忽略了关联数组$params的键,并将其解释为索引数组,从而在xml中产生错误的参数数据。也就是说,如果我以$params重新排序数据,$response就完全不同了:
$params = ['account' => '12345', 'user' => 'Hey'];
$response = $soapClient->__soapCall('<operation>', $params);
#6
2
If you create the object of SoapParam, This will resolve your problem. Create a class and map it with object type given by WebService, Initialize the values and send in the request. See the sample below.
如果您创建了SoapParam对象,这将解决您的问题。创建一个类并使用WebService提供的对象类型映射它,初始化值并发送请求。请参见下面的示例。
struct Contact {
function Contact ($pid, $pname)
{
id = $pid;
name = $pname;
}
}
$struct = new Contact(100,"John");
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "Contact","http://soapinterop.org/xsd");
$ContactParam = new SoapParam($soapstruct, "Contact")
$response = $client->Function1($ContactParam);
#7
1
read this;-
读到这,,
http://php.net/manual/en/soapclient.call.php
http://php.net/manual/en/soapclient.call.php
Or
或
This is a good example, for the SOAP function "__call". However it is deprecated.
这是一个很好的示例,用于SOAP函数“__call”。然而这是弃用。
<?php
$wsdl = "http://webservices.tekever.eu/ctt/?wsdl";
$int_zona = 5;
$int_peso = 1001;
$cliente = new SoapClient($wsdl);
print "<p>Envio Internacional: ";
$vem = $cliente->__call('CustoEMSInternacional',array($int_zona, $int_peso));
print $vem;
print "</p>";
?>
#8
0
You need declare class Contract
您需要声明类契约。
class Contract {
public $id;
public $name;
}
$contract = new Contract();
$contract->id = 100;
$contract->name = "John";
$params = array(
"Contact" => $contract,
"description" => "Barrel of Oil",
"amount" => 500,
);
or
或
$params = array(
$contract,
"description" => "Barrel of Oil",
"amount" => 500,
);
Then
然后
$response = $client->__soapCall("Function1", array("FirstFunction" => $params));
or
或
$response = $client->__soapCall("Function1", $params);
#9
0
You need a multi-dimensional array, you can try the following:
你需要一个多维数组,你可以试试下面的:
$params = array(
array(
"id" => 100,
"name" => "John",
),
"Barrel of Oil",
500
);
in PHP an array is a structure and is very flexible. Normally with soap calls I use an XML wrapper so unsure if it will work.
在PHP中,数组是一种结构,非常灵活。通常,对于soap调用,我使用XML包装器,不确定它是否能工作。
EDIT:
What you may want to try is creating a json query to send or using that to create a xml buy sort of following what is on this page: http://onwebdev.blogspot.com/2011/08/php-converting-rss-to-json.html
您可能想尝试的是创建一个json查询来发送或使用它来创建一个xml buy,类似于这个页面的内容:http://onwebdev.blogspot.com/2011/08/php-converting- rssto -json.html
#10
0
There is an option to generate php5 objects with WsdlInterpreter class. See more here: https://github.com/gkwelding/WSDLInterpreter
有一个用WsdlInterpreter类生成php5对象的选项。在这里看到更多:https://github.com/gkwelding/WSDLInterpreter
for example:
例如:
require_once 'WSDLInterpreter-v1.0.0/WSDLInterpreter.php';
$wsdlLocation = '<your wsdl url>?wsdl';
$wsdlInterpreter = new WSDLInterpreter($wsdlLocation);
$wsdlInterpreter->savePHP('.');
#1
143
This is what you need to do.
Just to know, I tried to recreate your situation...
只是想知道,我试着重现你的处境……
- For this example, I made a .NET sample webservice with a
WebMethod
calledFunction1
and these are the parameters: - 在这个示例中,我使用名为Function1的WebMethod制作了.NET示例webservice,这些参数是:
Function1(Contact Contact, string description, int amount)
Function1(联系人,字符串描述,int数量)
-
In which
Contact
is just a beanclass
that has getters and setters forid
andname
like in your case.在这种情况下,Contact只是一个bean类,它具有id和名称的getter和setter。
-
You can download this .NET sample webservice at:
你可以下载这个。net样例webservice:
https://www.dropbox.com/s/6pz1w94a52o5xah/11593623.zip
https://www.dropbox.com/s/6pz1w94a52o5xah/11593623.zip
The code.
This is what you need to do at PHP side:
这是在PHP方面需要做的:
(Tested and working)
(测试和工作)
<?php
/* Create a class for your webservice structure, in this case: Contact */
class Contact {
function Contact($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://localhost:10139/Service1.asmx?wsdl");
/* Fill your Contact Object */
$contact = new Contact(100, "John");
/* Set your parameters for the request */
$params = array(
"Contact" => $contact,
"description" => "Barrel of Oil",
"amount" => 500,
);
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("Function1", array($params));
/* Print webservice response */
var_dump($response);
?>
How I know this is working?
- If you do
print_r($params);
you will see this output, as your webservice expects: - 如果你print_r(params);您将看到这个输出,正如您的web服务所期望的:
Array ( [Contact] => Contact Object ( [id] => 100 [name] => John ) [description] => Barrel of Oil [amount] => 500 )
数组([Contact]] => Contact Object ([id] => 100 [name] => John) [description] => Barrel of Oil [amount] => 500)
- When I debugged the sample .NET webservice I got this:
- 当我调试。net web服务示例时,我得到了以下信息:
(As you can see, Contact
object is not null and also other parameters, that means your request was successfully done from PHP side).
(如您所见,Contact对象不是null和其他参数,这意味着您的请求已从PHP端成功完成)。
- The response from .NET sample webservice was the expected one and shown at PHP side:
- .NET示例webservice的响应是预期的,在PHP端显示:
object(stdClass)[3] public 'Function1Result' => string 'Detailed information of your request! id: 100, name: John, description: Barrel of Oil, amount: 500' (length=98)
对象(stdClass)[3] public 'Function1Result' => string '详细信息您的请求!身份证号:100,姓名:John,描述:油桶,金额:500'(长度=98)
Hope this helps :-)
希望这有助于:-)
#2
57
You can use SOAP services this way too:
您也可以使用SOAP服务:
<?php
//Create the client object
$soapclient = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('CountryName' => 'Spain', 'CityName' => 'Alicante');
$response = $soapclient->getWeather($params);
var_dump($response);
// Get the Cities By Country
$param = array('CountryName' => 'Spain');
$response = $soapclient->getCitiesByCountry($param);
var_dump($response);
This is an example with a real service, and it works.
这是一个实际服务的示例,它是有效的。
Hope this helps.
希望这个有帮助。
#3
26
First initialize webservices:
首先初始化web服务:
$client = new SoapClient("http://example.com/webservices?wsdl");
Then set and pass the parameters:
然后设置并传递参数:
$params = array (
"arg0" => $contactid,
"arg1" => $desc,
"arg2" => $contactname
);
$response = $client->__soapCall('methodname', array($params));
Note that the method name is available in WSDL as operation name, e.g.:
注意,方法名在WSDL中作为操作名可用,例如:
<operation name="methodname">
#4
18
I don't know why my web service has the same structure with you but it doesn't need Class for parameter, just is array.
我不知道为什么我的web服务和你有相同的结构,但它不需要类参数,只是数组。
For example: - My WSDL:
例如:-我的WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://www.kiala.com/schemas/psws/1.0">
<soapenv:Header/>
<soapenv:Body>
<ns:createOrder reference="260778">
<identification>
<sender>5390a7006cee11e0ae3e0800200c9a66</sender>
<hash>831f8c1ad25e1dc89cf2d8f23d2af...fa85155f5c67627</hash>
<originator>VITS-STAELENS</originator>
</identification>
<delivery>
<from country="ES" node=””/>
<to country="ES" node="0299"/>
</delivery>
<parcel>
<description>Zoethout thee</description>
<weight>0.100</weight>
<orderNumber>10K24</orderNumber>
<orderDate>2012-12-31</orderDate>
</parcel>
<receiver>
<firstName>Gladys</firstName>
<surname>Roldan de Moras</surname>
<address>
<line1>Calle General Oraá 26</line1>
<line2>(4º izda)</line2>
<postalCode>28006</postalCode>
<city>Madrid</city>
<country>ES</country>
</address>
<email>gverbruggen@kiala.com</email>
<language>es</language>
</receiver>
</ns:createOrder>
</soapenv:Body>
</soapenv:Envelope>
I var_dump:
我var_dump:
var_dump($client->getFunctions());
var_dump($client->getTypes());
Here is result:
这里是结果:
array
0 => string 'OrderConfirmation createOrder(OrderRequest $createOrder)' (length=56)
array
0 => string 'struct OrderRequest {
Identification identification;
Delivery delivery;
Parcel parcel;
Receiver receiver;
string reference;
}' (length=130)
1 => string 'struct Identification {
string sender;
string hash;
string originator;
}' (length=75)
2 => string 'struct Delivery {
Node from;
Node to;
}' (length=41)
3 => string 'struct Node {
string country;
string node;
}' (length=46)
4 => string 'struct Parcel {
string description;
decimal weight;
string orderNumber;
date orderDate;
}' (length=93)
5 => string 'struct Receiver {
string firstName;
string surname;
Address address;
string email;
string language;
}' (length=106)
6 => string 'struct Address {
string line1;
string line2;
string postalCode;
string city;
string country;
}' (length=99)
7 => string 'struct OrderConfirmation {
string trackingNumber;
string reference;
}' (length=71)
8 => string 'struct OrderServiceException {
string code;
OrderServiceException faultInfo;
string message;
}' (length=97)
So in my code:
所以在我的代码:
$client = new SoapClient('http://packandship-ws.kiala.com/psws/order?wsdl');
$params = array(
'reference' => $orderId,
'identification' => array(
'sender' => param('kiala', 'sender_id'),
'hash' => hash('sha512', $orderId . param('kiala', 'sender_id') . param('kiala', 'password')),
'originator' => null,
),
'delivery' => array(
'from' => array(
'country' => 'es',
'node' => '',
),
'to' => array(
'country' => 'es',
'node' => '0299'
),
),
'parcel' => array(
'description' => 'Description',
'weight' => 0.200,
'orderNumber' => $orderId,
'orderDate' => date('Y-m-d')
),
'receiver' => array(
'firstName' => 'Customer First Name',
'surname' => 'Customer Sur Name',
'address' => array(
'line1' => 'Line 1 Adress',
'line2' => 'Line 2 Adress',
'postalCode' => 28006,
'city' => 'Madrid',
'country' => 'es',
),
'email' => 'test.ceres@yahoo.com',
'language' => 'es'
)
);
$result = $client->createOrder($params);
var_dump($result);
but it successfully!
但是它成功!
#5
2
First, use SoapUI to create your soap project from the wsdl. Try to send a request to play with the wsdl's operations. Observe how the xml request composes your data fields.
首先,使用SoapUI从wsdl创建soap项目。尝试发送一个请求来处理wsdl的操作。观察xml请求如何组成数据字段。
And then, if you are having problem getting SoapClient acts as you want, here is how I debug it. Set the option trace so that the function __getLastRequest() is available for use.
然后,如果您在获取SoapClient行为方面遇到了问题,我将通过以下方法进行调试。设置选项跟踪,使函数__getLastRequest()可用。
$soapClient = new SoapClient('http://yourwdsdlurl.com?wsdl', ['trace' => true]);
$params = ['user' => 'Hey', 'account' => '12345'];
$response = $soapClient->__soapCall('<operation>', $params);
$xml = $soapClient->__getLastRequest();
Then the $xml variable contains the xml that SoapClient compose for your request. Compare this xml with the one generated in the SoapUI.
然后$xml变量包含SoapClient为您的请求编写的xml。将此xml与SoapUI中生成的xml进行比较。
For me, SoapClient seems to ignore the keys of the associative array $params and interpret it as indexed array, causing wrong parameter data in the xml. That is, if I reorder the data in $params, the $response is completely different:
对我来说,SoapClient似乎忽略了关联数组$params的键,并将其解释为索引数组,从而在xml中产生错误的参数数据。也就是说,如果我以$params重新排序数据,$response就完全不同了:
$params = ['account' => '12345', 'user' => 'Hey'];
$response = $soapClient->__soapCall('<operation>', $params);
#6
2
If you create the object of SoapParam, This will resolve your problem. Create a class and map it with object type given by WebService, Initialize the values and send in the request. See the sample below.
如果您创建了SoapParam对象,这将解决您的问题。创建一个类并使用WebService提供的对象类型映射它,初始化值并发送请求。请参见下面的示例。
struct Contact {
function Contact ($pid, $pname)
{
id = $pid;
name = $pname;
}
}
$struct = new Contact(100,"John");
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "Contact","http://soapinterop.org/xsd");
$ContactParam = new SoapParam($soapstruct, "Contact")
$response = $client->Function1($ContactParam);
#7
1
read this;-
读到这,,
http://php.net/manual/en/soapclient.call.php
http://php.net/manual/en/soapclient.call.php
Or
或
This is a good example, for the SOAP function "__call". However it is deprecated.
这是一个很好的示例,用于SOAP函数“__call”。然而这是弃用。
<?php
$wsdl = "http://webservices.tekever.eu/ctt/?wsdl";
$int_zona = 5;
$int_peso = 1001;
$cliente = new SoapClient($wsdl);
print "<p>Envio Internacional: ";
$vem = $cliente->__call('CustoEMSInternacional',array($int_zona, $int_peso));
print $vem;
print "</p>";
?>
#8
0
You need declare class Contract
您需要声明类契约。
class Contract {
public $id;
public $name;
}
$contract = new Contract();
$contract->id = 100;
$contract->name = "John";
$params = array(
"Contact" => $contract,
"description" => "Barrel of Oil",
"amount" => 500,
);
or
或
$params = array(
$contract,
"description" => "Barrel of Oil",
"amount" => 500,
);
Then
然后
$response = $client->__soapCall("Function1", array("FirstFunction" => $params));
or
或
$response = $client->__soapCall("Function1", $params);
#9
0
You need a multi-dimensional array, you can try the following:
你需要一个多维数组,你可以试试下面的:
$params = array(
array(
"id" => 100,
"name" => "John",
),
"Barrel of Oil",
500
);
in PHP an array is a structure and is very flexible. Normally with soap calls I use an XML wrapper so unsure if it will work.
在PHP中,数组是一种结构,非常灵活。通常,对于soap调用,我使用XML包装器,不确定它是否能工作。
EDIT:
What you may want to try is creating a json query to send or using that to create a xml buy sort of following what is on this page: http://onwebdev.blogspot.com/2011/08/php-converting-rss-to-json.html
您可能想尝试的是创建一个json查询来发送或使用它来创建一个xml buy,类似于这个页面的内容:http://onwebdev.blogspot.com/2011/08/php-converting- rssto -json.html
#10
0
There is an option to generate php5 objects with WsdlInterpreter class. See more here: https://github.com/gkwelding/WSDLInterpreter
有一个用WsdlInterpreter类生成php5对象的选项。在这里看到更多:https://github.com/gkwelding/WSDLInterpreter
for example:
例如:
require_once 'WSDLInterpreter-v1.0.0/WSDLInterpreter.php';
$wsdlLocation = '<your wsdl url>?wsdl';
$wsdlInterpreter = new WSDLInterpreter($wsdlLocation);
$wsdlInterpreter->savePHP('.');