【问题标题】:gSoap EWS "Error Schema Validation"gSoap EWS“错误模式验证”
【发布时间】:2015-09-19 01:48:56
【问题描述】:

我在使用 ews(gSoap) 进行 GetServerTimeZones 操作时遇到了一些问题。

我的客户代码是:

//request
ews__GetServerTimeZonesType *zoneReq = new ews__GetServerTimeZonesType();
zoneReq->Ids = new ns1__NonEmptyArrayOfTimeZoneIdType();
zoneReq->Ids->Id.push_back("Eastern Standard Time");

bool val = false;
zoneReq->ReturnFullTimeZoneData = &val;

//response
__ews__GetServerTimeZonesResponse resp;


if( proxy->GetServerTimeZones(zoneReq, resp) == SOAP_OK)
    std::cout <<  "Works!!" << std::endl;

编译成功后,运行时出现这个soap错误错误:

SOAP 1.1 fault: ns1:ErrorSchemaValidation[no subcode]
"The request failed schema validation: This is an invalid xsi:type 'http://schemas.microsoft.com/exchange/services/2006/messages:GetServerTimeZonesType'." Detail: <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>

发送的日志是:

<?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:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
        <ews:GetServerTimeZones xsi:type="ews:GetServerTimeZonesType">
            <ews:Ids>
                <ns1:Id>Eastern Standard Time</ns1:Id>
            </ews:Ids>
        </ews:GetServerTimeZones>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

并且接收日志是:

HTTP/1.1 500 Internal Server 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:ErrorSchemaValidation
            </faultcode>
            <faultstring xml:lang="en-US">The request failed schema validation: This is an invalid xsi:type 'http://schemas.microsoft.com/exchange/services/2006/messages:GetServerTimeZonesType'.
            </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>396</t:LinePosition>
                    <t:Violation>This is an invalid xsi:type 'http://schemas.microsoft.com/exchange/services/2006/messages:GetServerTimeZonesType'.</t:Violation>
                </t:MessageXml>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

我在这里做错了什么?任何帮助表示赞赏。如果您想要更多代码,我也会为您提供。谢谢。

更新: Request 的实际 XML 文件是:

<?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:ns1="http://schemas.microsoft.com/exchange/services/2006/types"
  xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
 <SOAP-ENV:Header>
  <ns1:MailboxCulture></ns1:MailboxCulture>
  <ns1:RequestServerVersion Version="Exchange2013_SP1">
  </ns1:RequestServerVersion>
 </SOAP-ENV:Header>
 <SOAP-ENV:Body>
   <ews:GetServerTimeZones ReturnFullTimeZoneData="false">
    <ews:Ids>
     <ns1:Id></ns1:Id>
     <ns1:Id></ns1:Id>
    </ews:Ids>
   </ews:GetServerTimeZones>

 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是在 SENT 日志文件中,ReturnFullTimeZoneData="false" 不存在,所以我不确定,会不会是这个问题的原因?

更新(2):

这是命名空间映射表-

#include "soapH.h"
SOAP_NMAC struct Namespace namespaces[] =
{
    {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
    {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL},
    {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
    {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
    {"ns1", "http://schemas.microsoft.com/exchange/services/2006/types", NULL, NULL},
    {"ews", "http://schemas.microsoft.com/exchange/services/2006/messages", NULL, NULL},
    {NULL, NULL, NULL, NULL}
};

谁能告诉我这张表是否需要改变?谢谢。

【问题讨论】:

    标签: c++ xml exchangewebservices gsoap soapfault


    【解决方案1】:

    由于无法访问消息和类型模式,我的评论只是一个最佳猜测。首先,由于类型模式与消息模式是分开的,我怀疑ewsns1:idxsi:type 中使用的错误名称空间前缀,应该是ns1。其次,xsi:type 可能因为从基类型继承/扩展而出现在那里。我的建议是使用选项 -P 运行 wsdl2h 以删除源自 xsd:anyType 根类型的不必要的 xsi:type 属性。如果这没有帮助,请尝试运行时标志 SOAP_XML_NOTYPE 来初始化 soap 上下文,这将删除 all xsi:type 属性。但是注意派生类型的反序列化(需要xsi:type 将失败。但说真的,xsi:type 是根据架构对这种类型的定义设置的,所以有可能与这些定义和上游接收者的 XML API 不匹配。

    【讨论】:

      【解决方案2】:

      我似乎无法掌握任何版本的 EWS 的架构,但我会质疑 ews:GetServerTimeZonesType 是否具有正确的命名空间前缀。我希望它是type,而不是message(无论区别是什么意思),但ews 绑定到http://schemas.microsoft.com/exchange/services/2006/messages

      我也不知道您正在使用的库,但其中似乎没有任何内容可以让您选择控制 xsi:type 注释的添加,而且它似乎正在这样做本身。所以这里对我来说仍然有一些神秘的事情发生。

      【讨论】:

      • 嗨@Tom W,gSoap 库的官方文档链接:genivia.com/doc/soapdoc2.html#tth_sEc7.1.2,我认为命名空间前缀是正确的,因为在 services.h 文件中提到的约定是:ews = "http://schemas.microsoft.com/exchange/services/2006/messages"ns1 = "http://schemas.microsoft.com/exchange/services/2006/types"
      • @IStar 我有同样的疑问,你可能在下面的链接中请帮助我。 stackoverflow.com/questions/19562854/…
      • 嗨@Tom W,我认为你是对的,问题可能就在那里,但你知道如何解决吗?谢谢。
      • 嗨@Tom 我已经在代码中使用了文档/文字样式,即使我已经使用 -t 命令添加了 xsi:type ,但问题仍然存在。我的 SENT 日志中的更改是:&lt;SOAP-ENV:Body&gt; &lt;ews:GetServerTimeZones xsi:type="ews:GetServerTimeZonesType" ReturnFullTimeZoneData="false"&gt; &lt;ews:Ids xsi:type="ns1:NonEmptyArrayOfTimeZoneIdType"&gt; &lt;ns1:Id xsi:type="xsd:string"&gt;Eastern Standard Time&lt;/ns1:Id&gt; &lt;/ews:Ids&gt; &lt;/ews:GetServerTimeZones&gt; &lt;/SOAP-ENV:Body&gt;
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2017-11-12
      • 2020-03-03
      • 2017-12-11
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多