Question

all. I have next problem. I want to connect to mailbox with Impersonation rights. User Admin has Impersonation rights, and i know how to do it in C#. I have next code:

ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy(endpoint.c_str());
soap *pSoap = proxy->soap;
pSoap->userid = "Admin";
pSoap->passwd = "PASSWORD";
pSoap->ntlm_challenge = "";
pSoap->authrealm = "Ursa-Minor";

pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION;
pSoap->keep_alive = true;   
soap_mode(pSoap,SOAP_IO_KEEPALIVE);

string smtp = "User1@no-such-email.com";

pSoap->header = new struct SOAP_ENV__Header();
pSoap->header->ns3__RequestServerVersion = new _ns3__RequestServerVersion();
pSoap->header->ns3__RequestServerVersion->Version = ns3__ExchangeVersionType__Exchange2007_USCORESP1;

if(!smtp.empty())
{
    pSoap->header->ns3__ExchangeImpersonation = new ns3__ExchangeImpersonationType();
    pSoap->header->ns3__ExchangeImpersonation->ConnectingSID = new ns3__ConnectingSIDType();
    pSoap->header->ns3__ExchangeImpersonation->ConnectingSID->union_ConnectingSIDType.PrimarySmtpAddress = &smtp;
    pSoap->header->ns3__ExchangeImpersonation->ConnectingSID->__union_ConnectingSIDType = 3;
}

As a resault i have this request:

POST /ews/Exchange.asmx HTTP/1.1
Host: 192.168.0.49
User-Agent: gSOAP/2.8
Content-Type: text/xml; charset=utf-8
Content-Length: 1093
Connection: keep-alive
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGoAAAAYABgAggAAABoAGgBAAAAACAAIAFoAAAAIAAgAYgAAAAAAAACaAAAABYKBAk4ATwAtAFMAVQBDAEgALQBFAE0AQQBJAEwASQB2AGEAbgBJAHYAYQBuAKEcAIkJWxEWBsuOv7MjtBpHLDWAL8JCTJ28+8Uotrb6QFrMa88HavXFTG1ddTR1VQ==
SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder"

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Header>
    <ns3:ExchangeImpersonation SOAP-ENV:mustUnderstand="1">
        <ns3:ConnectingSID>
            <ns3:PrimarySmtpAddress>User1@no-such-email.com</ns3:PrimarySmtpAddress>
        </ns3:ConnectingSID>
    </ns3:ExchangeImpersonation>
<ns3:RequestServerVersion SOAP-ENV:mustUnderstand="1" Version="Exchange2007_SP1"></ns3:RequestServerVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetFolder xsi:type="ns1:GetFolderType"><ns1:FolderShape><ns3:BaseShape>AllProperties</ns3:BaseShape></ns1:FolderShape><ns1:FolderIds><ns3:DistinguishedFolderId Id="msgfolderroot" xsi:type="ns3:DistinguishedFolderIdType"></ns3:DistinguishedFolderId></ns1:FolderIds></ns1:GetFolder></SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

It seems legit, but server response return error:

    <?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>    
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInternalServerError</faultcode>
            <faultstring xml:lang="en-US">An internal server error occurred. The operation failed.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInternalServerError</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">An internal server error occurred. The operation failed.</e:Message>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>
ns3:ExchangeImpersonation> !!! THERE IS SOMETHING WRONG
<ns3:RequestServerVersion SOAP-ENV:mustUnderstand="1" Version="Exchange2007_SP1"></ns3:RequestServerVersion>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ns1:GetFolder xsi:type="ns1:GetFolderType">
        <ns1:FolderShape><ns3:BaseShape>AllProperties</ns3:BaseShape></ns1:FolderShape>
        <ns1:FolderIds>
            <ns3:DistinguishedFolderId Id="msgfolderroot" xsi:type="ns3:DistinguishedFolderIdType"></ns3:DistinguishedFolderId>
        </ns1:FolderIds>
    </ns1:GetFolder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response even doesn`t have well formed xml. Well, i don`t know how to solve this problem at this moment.

Was it helpful?

Solution

To remove the mustunderstand attribute from the wsdl2h-generated source code declarations that produces the SOAP Header, use wsdl2h option -k.

OTHER TIPS

This is an old question, but I had a little update on it: To those that may be experiencing issues with mustunderstand appearing due to using some gsoap plugin (for me it was with the wsse plugin, I know mustunderstand is part of that standard, but the service I am calling does not)

Anyway, to solve this I edited the header files in gsoap/import to remove the mustunderstand parts. This stopped the wsse header having mustunderstand included.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top