我正在使用 PERL 和 SOAP::Lite 对 MS Exchange Web 服务进行肥皂调用。我已经弄清楚了身份验证并正在使用 Oauth 令牌进行调用。我正在尝试调用此处记录的 GetInboxRules 。
基本上电话需要看起来像这样。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP1" />
</soap:Header>
<soap:Body>
<m:GetInboxRules>
<m:MailboxSmtpAddress>User1@Contoso.com</m:MailboxSmtpAddress>
</m:GetInboxRules>
</soap:Body>
</soap:Envelope>
我的第一次尝试使用了以下代码:
my $client = SOAP::Lite->service('file://home/auth/work/src/ben/services.wsdl')->proxy('https://outlook.office365.com/EWS/Exchange.asmx');
$client->readable(1)->autotype(0)->outputxml('true');
$client->ns('http://schemas.microsoft.com/exchange/services/2006/messages', 'm');
my $ua = $client->schema->useragent;
$ua->default_header('Authorization' => $auth_header);
$ua->default_header('Content-Type' => 'application/xml');
$client->schema->useragent($ua);
$client->transport->http_request->headers->push_header('Authorization'=> $auth_header);
# WITH URI
my $som = $client->call('GetInboxRules', SOAP::Data->name('MailboxSmtpAddress')->value('eg7636@foo.com')->uri('http://schemas.microsoft.com/exchange/services/2006/messages'));
这产生了以下 XML 以及 500 内部服务器错误说明:
“请求未通过架构验证:命名空间“ http://schemas.microsoft.com/exchange/services/2006/messages ”中的元素“GetInboxRules”具有无效的子元素“MailboxSmtpAddress”。预期的可能元素列表:“MailboxSmtpAddress”在命名空间' http://schemas.microsoft.com/exchange/services/2006/messages '"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<m:GetInboxRules>
<MailboxSmtpAddress>eg7636@foo.com</MailboxSmtpAddress>
</m:GetInboxRules>
</soap:Body>
</soap:Envelope>
我已经在设置名称空间,但为了尝试解决这个问题,我通过向 MailboxSmtpAddress 元素添加 uri 规范来指定名称空间my $som = $client->call('GetInboxRules', SOAP::Data->name('MailboxSmtpAddress')->value('eg7636@foo.com')->uri('http://schemas.microsoft.com/exchange/services/2006/messages'));
这产生了:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:namesp3="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<m:GetInboxRules>
<namesp3:MailboxSmtpAddress xmlns:namesp3="http://schemas.microsoft.com/exchange/services/2006/messages">eg7636@foo.com</namesp3:MailboxSmtpAddress>
</m:GetInboxRules>
</soap:Body>
</soap:Envelope>
然后是 400 Bad Request 响应。我猜测错误的请求响应是因为 MailboxSmtpAddress 标记中包含 url,但我不知道如何指定命名空间。
这是我第一次使用 SOAP,因此非常感谢任何建议。