xml - EWS SOAP Requests failing -
i using perl , soap::lite make soap calls ms exchange web services. have figured out authenticating , using oauth token make calls. trying call getinboxrules documented here.
basically call needs this.
<?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 first attempt used following code:
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'); $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); # uri $som = $client->call('getinboxrules', soap::data->name('mailboxsmtpaddress')->value('eg7636@foo.com')->uri('http://schemas.microsoft.com/exchange/services/2006/messages'));
this produced following xml along 500 internal server error stating:
"the request failed schema validation: element 'getinboxrules' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'mailboxsmtpaddress'. list of possible elements expected: 'mailboxsmtpaddress' in namespace '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>
i setting name space try , remedy specified names space mailboxsmtpaddress element adding uri specification my $som = $client->call('getinboxrules', soap::data->name('mailboxsmtpaddress')->value('eg7636@foo.com')->uri('http://schemas.microsoft.com/exchange/services/2006/messages'));
which produced:
<?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>
followed 400 bad request response. guessing bad request response because of url included in mailboxsmtpaddress tag don't know how else specify namespace.
this first time working soap suggestions appreciated.
a saint came rescue , presented me following code:
my $client = soap::lite ->readable(1) ->proxy('https://outlook.office365.com/ews/exchange.asmx') ->ns( 'http://schemas.microsoft.com/exchange/services/2006/types', 'typ') ->ns( 'http://schemas.microsoft.com/exchange/services/2006/messages', 'mes') ->envprefix('soapenv') ->autotype(0); $client->serializer->{'_attr'}{'{http://schemas.xmlsoap.org/soap/envelope/}encodingstyle'} = undef; $client->transport->default_header('authorization' => $auth_header); $client->transport->default_header('x-anchormailbox' => 'eg7636@waynestatetest.onmicrosoft.com'); $client->transport->default_header('x-owa-explicitlogonuser' => 'eg7636@waynestatetest.onmicrosoft.com'); @header = ( soap::header->name('typ:requestserverversion')->attr({'version' => 'exchange2015'}), soap::header->name('typ:exchangeimpersonation')->value(\soap::header->name('typ:connectingsid') ->value(\soap::header->name('typ:smtpaddress')->value('eg7636@foo.com'))) ); @param; $method; @param = ( soap::data->name('mes:mailboxsmtpaddress', 'eg7636@foo.com'), ); $method = soap::data->name('mes:getinboxrules'); $response = $client->call($method => (@param, @header)); print dumper($response);
this resulted in namespace tag being placed on elements being passed method call , corrected issues had formatting of header.
the following xml came code:
<soapenv:envelope xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <soapenv:header> <typ:requestserverversion version="exchange2015" /> <typ:exchangeimpersonation> <typ:connectingsid> <typ:smtpaddress>eg7636@foo.com</typ:smtpaddress> </typ:connectingsid> </typ:exchangeimpersonation> </soapenv:header> <soapenv:body> <mes:getinboxrules> <mes:mailboxsmtpaddress>eg7636@foo.com</mes:mailboxsmtpaddress> </mes:getinboxrules> </soapenv:body> </soapenv:envelope>
this produced successful response microsoft.
Comments
Post a Comment