肥皂 - 一个字符串的列表被发送为字符串

时间:2018-01-12 08:14:37

标签: java php string soap wsdl

我从Java后端通过SOAP发送一个字符串的StringList到PHP客户端。

WSDL:

<xs:element name="getSearchHintResponse">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="1" name="hint">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="1" minOccurs="1" name="text" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

它运行正常,当我发送超过一个字符串,但什么时候只有一个字符串发送,然后php端无法识别,它是一个字符串数组和SOAP(或PHP?)以某种方式转换它是一个字符串。

一个字符串的Php日志:

object(stdClass)#260 (1) {
    ["hint"]=>
    object(stdClass)#261 (1) {
        ["text"]=>
        string(5) "ales "
    }
}

包含更多字符串的Php日志:

object(stdClass)#260 (1) {
    ["hint"]=>
    array(2) {
        [0]=>
        object(stdClass)#261 (1) {
            ["text"]=>
            string(4) "ale  "
        }
        [1]=>
        object(stdClass)#262 (1) {
            ["text"]=>
            string(5) "ales "
        }
    }
}

是否有可能,我如何在Java后端(创建WSDL的地方)修复此问题,或者我是否需要强制php dev检查它是否为String?

编辑:

Java端点:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getSearchHintRequest")
@ResponsePayload
public GetSearchHintResponse getSearchHintRequest(@RequestPayload GetSearchHintRequest request) throws Exception {
        GetSearchHintResponse response = new GetSearchHintResponse();
        List<GetSearchHintResponse.Hint> hints = response.getHint();
        Collection<? extends String> hintsStr = searchComponent.getSearchHint(request.getBeginning(),
                request.getCollections(), request.getHintCount());
        for (String hintStr : hintsStr) {
            GetSearchHintResponse.Hint hint = new GetSearchHintResponse.Hint();
            hint.setText(hintStr + "\t");
            hints.add(hint);
        }
        return response;
}

1 个答案:

答案 0 :(得分:0)

正如XtremeBaumer在评论中提到的那样:

  

你可以检查你身边的长度,如果只有1个元素,你可以在数组中添加一个空字符串(&#34;&#34;)。我认为应该首先解决它,但我不确定对php dev的影响 - XtremeBaumer 1月12日8:30

这是一个很脏的方式,有空div,但它有效。

相关问题