我正在尝试使用这个 WSDL向一个新闻通讯服务发送 SOAP 请求。
以下是我的 PHP 代码:
$client = new SoapClient($wsdl_url, array(
'login' => 'myusername',
'password' => 'mypassword',
'trace' => true
));
$client->AddSubscriber(
new SoapParam('MyFirstName', 'FirstName'),
new SoapParam('MyLastName', 'LastName'),
new SoapParam('myemail@someaddress.com', 'Email')
);
我正在遇到异常:
End element 'Body' from namespace 'schemas.xmlsoap.org/soap/envelope/' expected. Found element 'LastName' from namespace ''. Line 2, position 156.
以下是服务对AddSubscriber的期望内容:
以下是服务对AddSubscriber的期望内容:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="admin.ekeryx.com">
<Username>string</Username>
<Password>string</Password>
<AccountID>string</AccountID>
</AuthHeader>
</soap:Header>
<soap:Body>
<AddSubscriber xmlns="admin.ekeryx.com">
<subscriber>
<ID>string</ID>
<FirstName>string</FirstName>
<LastName>string</LastName>
<Email>string</Email>
</subscriber>
<overwritable>boolean</overwritable>
</AddSubscriber>
</soap:Body>
</soap:Envelope>
以下是发送的内容:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="tempuri.org/">
<SOAP-ENV:Body>
<ns1:AddSubscriber/>
<LastName>MyLastName</LastName>
<Email>myemail@someaddress.com</Email>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我对SOAP并不是很熟悉,一直在各处寻找文档,但似乎找不到一个非常好的参考资料来指导我的工作。
非常感谢您提供任何帮助!
谢谢。您能给我一个例子吗?我正在查看PHP网站上的示例,其中显示:
<?php
class SOAPStruct {
function SOAPStruct($s, $i, $f)
{
$this->varString = $s;
$this->varInt = $i;
$this->varFloat = $f;
}
}
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
$struct = new SOAPStruct('arg', 34, 325.325);
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPStruct", "http://soapinterop.org/xsd");
$client->echoStruct(new SoapParam($soapstruct, "inputStruct"));
?>
你是说我需要创建一个Subscriber PHP类,分配所有变量$this->FirstName = $first_name等等...然后将其放入具有编码SOAP_ENC_OBJECT的SoapVar中吗?我如何更好地表示订阅者结构?