gSoap EWS“错误 500:内部服务器错误”

2024-01-10

我在使用 ews(gSoap) 时遇到一些问题。

我有下一个代码:

ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy(endpoint.c_str());

soap *pSoap = proxy->soap;
pSoap->userid = "Ivan1";
pSoap->passwd = "1";
pSoap->ntlm_challenge = "";
pSoap->authrealm = "Ursa-Minor";

pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION;
pSoap->keep_alive = true;   
pSoap->mode = SOAP_IO_KEEPALIVE;

//get root folder ID
ns3__DistinguishedFolderIdType *dfit = new ns3__DistinguishedFolderIdType();
dfit->Id = ns3__DistinguishedFolderIdNameType__inbox;

//set the props that we want to retrieve
ns3__FolderResponseShapeType *frst = new ns3__FolderResponseShapeType();
frst->BaseShape = ns3__DefaultShapeNamesType__AllProperties;

//get folder
ns1__GetFolderType *gftRoot = new ns1__GetFolderType();
gftRoot->FolderIds = new ns3__NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__size_NonEmptyArrayOfBaseFolderIdsType = 1;
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType = new __ns3__union_NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderIds = (ns3__NonEmptyArrayOfBaseFolderIdsType*)dfit;
gftRoot->FolderShape = frst;
__ns1__GetFolderResponse response;

int ret = proxy->GetFolder(gftRoot, response);

我正在使用 OpenSSL 和 NTLM 库(WITH_OPENSSL、WITH_NTLM)。

结果 gSoap 生成了这个 SOAP:

<?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:RequestServerVersion SOAP-ENV:mustUnderstand="1" Version="Exchange2010">
</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 Id="inbox" xsi:type="ns3:DistinguishedFolderIdType"> </ns1:FolderIds>
</ns1:GetFolder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

服务器响应:

HTTP/1.1 500 Internal Server Error
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.0
Set-Cookie: exchangecookie=88bb510ab2ef4191a42c6cf9aada1614; expires=Fri, 24-Oct-2014 09:45:45 GMT; path=/; HttpOnly
X-EwsPerformanceData: RpcC=0;RpcL=0;LdapC=0;LdapL=0;
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 24 Oct 2013 09:45:45 GMT
Connection: close

5d0
<?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:ErrorSchemaValidation</faultcode>
            <faultstring xml:lang="en-US">The request failed schema validation: The xsi:type attribute value 'http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdType' is not valid for the element 'http://schemas.microsoft.com/exchange/services/2006/messages:FolderIds', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.</faultstring>
            <detail>
                <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
                <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
                <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
                    <t:LineNumber>2</t:LineNumber>
                    <t:LinePosition>519</t:LinePosition>
                    <t:Violation>The xsi:type attribute value 'http://schemas.microsoft.com/exchange/services/2006/types:DistinguishedFolderIdType' is not valid for the element 'http://schemas.microsoft.com/exchange/services/2006/messages:FolderIds', either because it is not a type validly derived from the type in the schema, or because it has xsi:type derivation blocked.
                    </t:Violation>
                </t:MessageXml>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

正如你所看到的,问题出在线上

<ns1:FolderIds Id="inbox" xsi:type="ns3:DistinguishedFolderIdType"

服务器不希望在这一行中看到 xsi:type="ns3:DistinguishedFolderIdType"。在原始 SOAP 中,它看起来像:

 <FolderIds>
  <DistinguishedFolderId Id="inbox" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" /> 
  </FolderIds>

所以。如何解决这个问题呢?


IStar,

首先,我不熟悉 gSOAP,也不熟悉这种语法。事实上,我并不指望回答你的问题,但我会尝试一下。尽管如此,gSOAP 正在尝试创建 EWS 不支持的 XML。我认为以下几行是不正确的,可能还需要一两行:

gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderIds = (ns3__NonEmptyArrayOfBaseFolderIdsType*)dfit;

我认为第二行是指示 gSOAP 将FolderIds 元素设置为不应该的元素。看起来FolderIds 和DistinguishedFolderId 元素结构存在某种合并。

也许它应该看起来像这样:

ns3__NonEmptyArrayOfBaseFolderIdsType *fids = new ns3__NonEmptyArrayOfBaseFolderIdsType();
fids->DistinguishedFolderId = dfit
fids->__size_NonEmptyArrayOfBaseFolderIdsType = 1;
gftRoot->FolderIds = fids;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gSoap EWS“错误 500:内部服务器错误” 的相关文章

随机推荐