【问题标题】:EWS gSoap Connection with ImpersonationEWS gSoap 连接与模拟
【发布时间】:2014-03-04 01:13:42
【问题描述】:

所有。我有下一个问题。我想连接到具有模拟权限的邮箱。用户管理员具有模拟权限,我知道如何在 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。 好吧,我现在不知道如何解决这个问题。

【问题讨论】:

  • 我在代码中找到了一行,其中 'SOAP-ENV:mustUnderstand="1"' 写入请求并对其进行了注释。所以现在我只有&lt;ns3:ExchangeImpersonation&gt;。它有效。但是,我认为,its not right to do like that. How can i remove mustUnderstand="1"` 来自我的请求?

标签: c++ exchangewebservices gsoap


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      相关资源
      最近更新 更多