2013-10-30 90 views
1

全部。我有下一個問題。我想連接到具有模擬權限的郵箱。用戶管理員具有模擬權限,我知道如何在C#中執行此操作。 我有下面的代碼:EWS gSoap模擬連接

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 = "[email protected]"; 

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; 
} 

作爲resault我有這樣的要求:

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>[email protected]</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> 

似乎合法的,但服務器響應返回錯誤:

<?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> 

響應,甚至不`噸已經很好地形成了xml。 那麼,我現在不知道如何解決這個問題。

+0

我在代碼中找到了一行,其中'SOAP-ENV:mustUnderstand =「1」'寫入請求並對其進行評論。所以現在我只有''。它的工作原理。但是,我認爲,這樣做是不對的。我如何從我的請求中刪除'mustUnderstand =「1」'? – IStar

回答

1

要從生成SOAP Header的wsdl2h生成的源代碼聲明中除去mustunderstand屬性,請使用wsdl2h選項-k。

+0

非常感謝! – IStar

1

這是一個老問題,但我對它有一點點更新:對於那些可能遇到的問題,肯定會出現,因爲使用了一些gsoap插件(對我來說,這是與wsse插件,我知道mustunderstand是部分的標準,但我打電話的服務不)

無論如何,要解決此問題,我編輯了gsoap/import中的頭文件以刪除mustunderstand部分。這阻止了必須包含的wsse頭文件。