1

全部。我有下一个问题。我想连接到具有模拟权限的邮箱。用户管理员具有模拟权限,我知道如何在 C# 中执行此操作。我有下一个代码:

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

作为结果,我有这个要求:

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>

看起来合法,但服务器响应返回错误:

    <?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。好吧,我现在不知道如何解决这个问题。

4

2 回答 2

1

mustunderstand要从wsdl2h 生成的生成 SOAP 标头的源代码声明中删除该属性,请使用 wsdl2h 选项 -k。

于 2013-10-30T15:39:43.010 回答
1

这是一个老问题,但我对此进行了一些更新:对于那些可能因使用某些 gsoap 插件而出现 mustunderstand 问题的人(对我来说是 wsse 插件,我知道 mustunderstand 是该标准的一部分,但我打电话的服务没有)

无论如何,为了解决这个问题,我编辑了 gsoap/import 中的头文件以删除必须理解的部分。这停止了​​包含 mustunderstand 的 wsse 标头。

于 2014-03-03T17:13:42.990 回答