使用 nuSoap 的 complexType [英] complexType with nuSoap

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

问题描述

我有这个 WDSL

<xsd:element name="elementname">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element maxOccurs="1" minOccurs="1" ref="miref"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

现在我必须通过 nuSoap 创建它,但无论如何我都找不到在 complexType 上省略 de type 和 name 并在元素内设置 complexType.

Now I have to create that via nuSoap but I can't find anyway to omit de type and name on the complexType and set the complexType inside of an element.

所以如果我想创建一个元素,我使用这个代码:

So if I want to create an element I use this code:

$server->wsdl->AddElement(  
        array('name' => 'example1', 'type' => ''
        )
); 

如果我想创建一个 complexType :

And if I want to create a complexType this other:

$server->wsdl->addComplexType(
    'example2',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'id_user' => array('type' => '', 'maxOccurs' => '1', 'minOccurs' => '1'),
    )
);   

所以这是我的问题:1] 我需要将该 complexType (example2) 放在另一个元素 (example1) 中.2] complexType 不应该在标签中包含他的名字,但是如果我不给它们类型和名称,函数 addComplexType() 和 addElement() 似乎不起作用.文档中还说明了它的需要:必须包含名称和类型的属性.

So this are my problems: 1] I need to put that complexType (example2) inside of the other element (example1). 2] The complexType shouldn't have his name inside the tag but the functions addComplexType() and addElement(), dosn't seem to work if I don't give them the Type and the Name. Also in the documentation is typified that it's need: attributes that must include name and type.

推荐答案

我不熟悉 nuSoap,但由于它基于原生 PHP SoapServer,我假设它是相似的.

I'm not familiar with nuSoap, but as it's based on native PHP SoapServer, I'm asuming it's similar.

基本上在使用 PHP 方法时,SoapServer 会根据附加的 XML Schema (XSD) 解析返回的对象.

Basicly when working with PHP methods, SoapServer will parse returned objects according to attached XML Schema (XSD).

每当您使用 complexType 时,您都应该有相应的已定义 PHP 类.StdClass 也可以工作,但定义结构显然更好.

Whenever you're working with complexType you should have corresponding defined PHP class. StdClass will work too, but it's obviously better to define structure.

$response = new stdClass();
$response->sequenceElement = 'value';
return $response;

显然,sequenceElement 名称必须与您所指的 XSD 类相匹配 (ref="miref").

Obviously, sequenceElement name must match XSD class you're refering to (ref="miref").

此外,如果您向 $response 添加其他数据,SoapServer 将忽略它,因为它没有在 XSD 中定义.

Moreover, if you add additional data to your $response, it will be ignored by SoapServer, since it's not defined in XSD.

这篇关于使用 nuSoap 的 complexType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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