简体   繁体   English

在wsdl中将任何模式元素与PHP SoapServer一起使用

[英]Using the any schema element in wsdl with PHP SoapServer

I can't seem to get the XSD element to work in my wsdl using PHP SoapServer. 我似乎无法使用PHP SoapServer在wsdl中使用XSD元素。 According to everything I have read and seeing how a couple of other companies implement "loose typed" wsdls. 根据所读内容,我看到了其他两家公司如何实施“松散式” wsdl。 The following should be sufficient for retrieving and sending records information. 以下内容足以检索和发送记录信息。

<complexType name="Record">
    <sequence>
        <any namespace="##targetNamespace" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
    </sequence>
</complexType>

Unfortunately, it seems that the php SoapServer class throws away any elements that are not strictly defined. 不幸的是,似乎php SoapServer类会丢弃所有未严格定义的元素。 What I get is empty records on create requests and send empty records on retrieve/filter requests, though the fields are clearly there before the SoapServer handling. 我得到的是创建请求上的空记录,并在检索/过滤器请求上发送空记录,尽管这些字段在SoapServer处理之前很明显。

If I specifically define the fields that are missing like this... 如果我专门定义像这样缺少的字段...

<complexType name="Record">
    <sequence>
        <element name="FirstName" type="xsd:string" minOccurs="0"/>
        <element name="LastName" type="xsd:string" minOccurs="0"/>
        <any namespace="##targetNamespace" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
    </sequence>
</complexType>

then all is well and those fields get passed to/from the client. 那么一切都很好,这些字段将传递到客户端或从客户端传递出去。 Am I missing something? 我想念什么吗? I have tried all of the namespace options ##any, ##local, etc. and the processContents options. 我已经尝试了所有名称空间选项## any,## local等以及processContents选项。 I just want to be able to send/return extra fields of a record regardless if they are detailed out in the schema or not. 我只希望能够发送/返回记录的额外字段,无论它们是否在架构中详细说明。

You need to use the SoapVar object in your return object that you pass to the soap response. 您需要在传递给soap响应的返回对象中使用SoapVar对象。 In your case the object returned should look something like this. 在您的情况下,返回的对象应如下所示。

$recordObject = new stdClass;
$recordObject->prop1 = 'prop1';
$recordObject->prop2 = 'prop2';

$soapReturnObject = new SoapVar($recordObject, SOAP_ENC_OBJECT);

See also : SOAP: Returning an array of xsd:any elements in PHP 另请参见: SOAP:返回xsd:PHP中的任何元素的数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM