在 PHP 中使用具有抽象类型的 WSDL [英] Using a WSDL with abstract types in PHP

查看:17
本文介绍了在 PHP 中使用具有抽象类型的 WSDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我们的 Web 应用程序和 Microsoft Exchange 2007 之间的集成.我正在使用 Exchange Web 服务 (EWS) 与 Exchange Server 进行通信.但是,我遇到了 WSDL 的一些问题.WSDL 中定义了几种具有抽象类型元素的类型.例如:

I'm working on an integration between our web application and Microsoft Exchange 2007. I am using Exchange Web Services (EWS) to communicate to the Exchange Server. However, I am running into some issues with the WSDL. There are several types defined in the WSDL that have elements of abstract types. For example:

<xs:complexType name="RestrictionType">
  <xs:sequence>
    <xs:element ref="t:SearchExpression"/>
  </xs:sequence>
</xs:complexType>

SearchExpression 是一个抽象类型.有几种扩展 SearchExpression 的类型,例如 ExistsType:

SearchExpression is an abtract type. There are several types that extend SearchExpression such as ExistsType:

<xs:complexType name="ExistsType"> 
  <xs:complexContent> 
    <xs:extension base="t:SearchExpressionType"> 
      ...
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
<xs:element name="Exists" type="t:ExistsType" substitutionGroup="t:SearchExpression"/>

我希望能够进行生成以下 XML 的有效调用:

I would expect to be able to make a valid call that produces the following XML:

<Restriction>
  <Exists>
    ...
  </Exists>
</Restriction>

但是,当我尝试使用 PHP 的 SoapClient 类进行调用时,我收到以下错误:

However, when I attempt to make the call using PHP's SoapClient class I receive the following error:

请求架构验证失败:元素 'http://schemas.microsoft.com/exchange/services/2006/types:SearchExpression' 是抽象的或其类型是抽象的.

The request failed schema validation: The element 'http://schemas.microsoft.com/exchange/services/2006/types:SearchExpression' is abstract or its type is abstract.

如果我将 RestrictionType 类型的定义修改为以下内容,则调用有效:

If I modify the definition of the RestrictionType type to the follow, the call works:

<xs:element name="Exists" type="t:ExistsType"/>

PHP 的 SOAP 处理是否无法正确处理 WSDL 中的抽象类型,还是 WSDL 本身有问题?WSDL 存储在本地,因此我可以在需要时对其进行编辑.

Is PHP's SOAP handling not able to properly handle abstract types in the WSDL, or could there be something wrong with the WSDL itself? The WSDL is stored locally so I can make edits to it if the need arrises.

提前感谢您的帮助.


我只是想澄清一下,我不是自己形成 XML 的.我正在使用以下应该创建正确 XML 的代码:


I just wanted to clarify that I am not forming the XML myself. I am using the following code that should be creating the proper XML:

$request->Restriction->IsGreaterThan->FieldURI->FieldURI =
  'item:DateTimeReceived';
$request->Restriction->IsGreaterThan->FieldURIOrConstant
  ->Constant->Value = date('c', $last_checked_time);

推荐答案

我找到了自己问题的答案.显然,当存在抽象类型时,PHP 的 SOAP 对象无法从我正在使用的对象结构中正确地形成 XML.为了解决这个问题,我编辑了 WSDL 并将对任何抽象类型的引用替换为对扩展它们的具体类型的引用.因此,对于上面的 RestrictionType 示例,我更改了架构定义以匹配以下内容:

I found the answer to my own question. Apparently PHP's SOAP object cannot properly form XML from the object structure I am using when there are abstract types. To combat the issue, I edited the WSDL and replaced references to any abstract types with references to the concrete types that extend them. So for the RestrictionType example above, I changed the schema definition to match the following:

<xs:complexType name="RestrictionType"> 
  <xs:choice maxOccurs ="unbounded">
    <xs:element ref="t:Exists"/>
    <xs:element ref="t:Excludes"/>
    <xs:element ref="t:IsEqualTo"/>
    <xs:element ref="t:IsNotEqualTo"/>
    <xs:element ref="t:IsGreaterThan"/>
    <xs:element ref="t:IsGreaterThanOrEqualTo"/>
    <xs:element ref="t:IsLessThan"/>
    <xs:element ref="t:IsLessThanOrEqualTo"/>
    <xs:element ref="t:Not"/>
    <xs:element ref="t:And"/>
    <xs:element ref="t:Or"/>
  </xs:choice>
</xs:complexType>

我希望这能帮助其他人.感谢所有花时间至少阅读我的帖子的人.

I hope this helps somebody else out. Thanks to all who took the time to at least read my post.

这篇关于在 PHP 中使用具有抽象类型的 WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆