0

我有一个用 C# 编写的 Web 服务。我从 PHP 调用这个 Web 服务的方法。所有期望原始参数的方法都很好用。不过,在尝试调用更复杂的方法时,我会收到异常。

这是我的 C#:

[WebMethod(Description = "Search components using the specified filters and username.")]
public DataSet Search(AttributeFilter[] filters, string username,
    int[] displayedAttributes, ComponentSearchOptions options,
    bool includeFlags, bool includeIcons)
{
    RemoteComponent remoteComponent = RemoteActivator.Create<RemoteComponent>();

    return remoteComponent.SearchComponents(filters, username, displayedAttributes, options, includeFlags, includeIcons);
}

这是相关的 WSDL:

<s:element name="Search">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="filters" type="tns:ArrayOfAttributeFilter"/>
            <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="displayedAttributes" type="tns:ArrayOfInt"/>
            <s:element minOccurs="1" maxOccurs="1" name="options" type="tns:ComponentSearchOptions"/>
            <s:element minOccurs="1" maxOccurs="1" name="includeFlags" type="s:boolean"/>
            <s:element minOccurs="1" maxOccurs="1" name="includeIcons" type="s:boolean"/>
        </s:sequence>
    </s:complexType>
</s:element>
<s:complexType name="ArrayOfAttributeFilter">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="unbounded" name="AttributeFilter" nillable="true" type="tns:AttributeFilter"/>
    </s:sequence>
</s:complexType>
<s:complexType name="AttributeFilter">
    <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="Attribute" type="s:int"/>
        <s:element minOccurs="1" maxOccurs="1" name="Comparison" type="tns:SearchComparison"/>
        <s:element minOccurs="0" maxOccurs="1" name="Value"/>
    </s:sequence>
</s:complexType>
<s:simpleType name="SearchComparison">
    <s:restriction base="s:string">
        <s:enumeration value="Equals"/>
        <s:enumeration value="GreaterThan"/>
        <s:enumeration value="GreaterThanOrEqual"/>
        <s:enumeration value="In"/>
        <s:enumeration value="LessThan"/>
        <s:enumeration value="LessThanOrEqual"/>
        <s:enumeration value="Like"/>
    </s:restriction>
</s:simpleType>
<s:simpleType name="ComponentSearchOptions">
    <s:list>
        <s:simpleType>
            <s:restriction base="s:string">
                <s:enumeration value="None"/>
                <s:enumeration value="IncludeCables"/>
                <s:enumeration value="IncludePorts"/>
            </s:restriction>
        </s:simpleType>
    </s:list>
</s:simpleType>
<s:element name="SearchResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="SearchResult">
                <s:complexType>
                    <s:sequence>
                    <s:element ref="s:schema"/>
                    <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>

这是我目前在 PHP 中的尝试:

$filters = array("filter" => (object)array("AttributeFilter" => (object)array("Attribute" => -2, "SearchComparison" => "Equals", "Value" => "110001")));
$search = $soapClient->Search($filters , "Administrator", NULL, "None", true, true);

我收到异常:

SOAP-ERROR:编码:对象没有“选项”属性

谁能指出我正确的方向?或者让我知道我正在尝试的东西是否在技术上是不可能的?

谢谢。

哦,还有,这是一个有效的 C# 测试用例:

private readonly ComponentSearchServicesSoapClient ComponentSearchServices = new ComponentSearchServicesSoapClient();

[Test]
public void TestSearchBarcode()
{
    AttributeFilter filter = new AttributeFilter
    {
        Attribute = -2,
        Comparison = SearchComparison.Equals,
        Value = "110001"
    };

    DataSet dataset = ComponentSearchServices.Search(new[] { filter }, "Administrator", null, ComponentSearchOptions.None, false, false);

    if (dataset.Tables.Count == 0 || dataset.Tables[0].Rows.Count != 1)
    {
        throw new Exception("Failed to properly search");
    }
}
4

1 回答 1

0

解决方案是两部分的问题。

进行调用的正确语法是:

$search = $soapClient->Search(array("filters" => array("AttributeFilter" => array('Attribute' => 310, 'Comparison' => 'Equals', 'Value' => 'Peering LAN')), 'username' => 'Administrator', 'displayedAttributes' => array(310), 'options' => 'None', 'includeFlags' => true, 'includeIcons' => true));

另一个问题是 AttributeFilter 类期望属性“值”是“对象”类型。将“值”更改为“字符串”类型会删除正在发生的序列化异常。

于 2013-03-08T00:23:59.733 回答