This is working sample code calling ResolveNames in EWS that I generated with SoapUI after retrieving the WDSL from Exchange Server:
<?xml version="1.0"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages">
<soapenv:Header><typ:RequestServerVersion Version="Exchange2010"/></soapenv:Header>
<soapenv:Body>
<mes:ResolveNames ReturnFullContactData="1" SearchScope="ActiveDirectoryContacts">
<mes:UnresolvedEntry>deve</mes:UnresolvedEntry>
</mes:ResolveNames>
</soapenv:Body>
</soapenv:Envelope>
This is the bare Delphi XE2 code that I use:
procedure TFrmTestEWS.BtnConnectClick(Sender: TObject);
var
lESB : ExchangeServicePortType;
lResNames : ResolveNames;
lReqVersion : RequestServerVersion;
lResResult : ResolveNamesResponse;
lServerVer : ServerVersionInfo;
lUnresolved : String;
begin
lServerVer := ServerVersionInfo.Create;
lResNames := ResolveNames.Create;
lReqVersion := RequestServerVersion.Create;
lUnresolved := 'Deve';
with lResNames do
begin
ReturnFullContactData := true;
SearchScope := ResolveNamesSearchScopeType.ActiveDirectoryContacts; // Scoped enums is on!
ParentFolderIds := nil;
UnresolvedEntry := lUnresolved;
end;
lReqVersion.Version := ExchangeVersionType.Exchange2010;
lESB := (HTTPRIO1 as ExchangeServicePortType);
lESB.ResolveNames(lResNames,
nil, // Impersonation
nil, // MailboxCulture
lReqVersion,
lResResult,
lServerVer);
It generates:
<?xml version="1.0"?>
<SOAP-ENV:Envelope
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">
<SOAP-ENV:Body xmlns:NS1="http://schemas.microsoft.com/exchange/services/2006/types">
<ResolveNames xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ReturnFullContactData="true" NS1:SearchScope="ActiveDirectoryContacts">
<UnresolvedEntry>deve</UnresolvedEntry>
</ResolveNames>
<MailboxCulture xsi:nil="true"/>
<ExchangeImpersonation xsi:nil="true"/>
<NS1:RequestServerVersion Version="Exchange2010"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The error I get:
The request failed schema validation: The 'http://schemas.microsoft.com/exchange/services/2006/types:SearchScope' attribute is not declared.
SearchScope is an attribute as defined in messages.xsd:
<!-- ResolveNames request -->
<xs:complexType name="ResolveNamesType">
<xs:complexContent>
<xs:extension base="m:BaseRequestType">
<xs:sequence>
<xs:element name="ParentFolderIds" type="t:NonEmptyArrayOfBaseFolderIdsType" minOccurs="0"/>
<xs:element name="UnresolvedEntry" type="t:NonEmptyStringType"/>
</xs:sequence>
<xs:attribute name="ReturnFullContactData" type="xs:boolean" use="required"/>
<xs:attribute name="SearchScope" type="t:ResolveNamesSearchScopeType" default="ActiveDirectoryContacts"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="ResolveNames" type="m:ResolveNamesType"/>
with in types.xsd:
<!-- ResolveNames request -->
<xs:simpleType name="ResolveNamesSearchScopeType">
<xs:restriction base="xs:string">
<xs:enumeration value="ActiveDirectory"/>
<xs:enumeration value="ActiveDirectoryContacts"/>
<xs:enumeration value="Contacts"/>
<xs:enumeration value="ContactsActiveDirectory"/>
</xs:restriction>
</xs:simpleType>
I thought that NS1:SearchScope="ActiveDirectoryContacts" is incorrect but leaving the NS1: out gives the same error.
Maybe postponing the Exchange xmlns specs for types and messages to within the SOAP-ENV:Body is the reason for the error?
Also, the NS1:RequestServerVersion Version="Exchange2010" not being in the SOAP_ENV:Header
looks suspect.
I have looked at some Google results but could not get it to work.
Basically my question is:
How can I move around the tags or xmlns attributes in the generated code until it works, without having to construct the entire SOAP myself?
And if that is not possible what approach is best so that I can still benefit from the imported type library? (Stuff like this?)
Thanks
Jan