dongxian4531
2013-03-07 19:02
浏览 48

通过PHP向从C#生成的WSDL发出SOAP请求,挣扎于语法

I've got a web service which was written in C#. I am calling this web service's methods from PHP. All of the methods which expect primitive parameters work great. I'm receiving exceptions when attempting to call a more complex method, though.

Here's my 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);
}

Here's the associated 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>

Here is my current attempt in PHP:

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

and I receive the exception:

SOAP-ERROR: Encoding: object has no 'options' property

Could anyone point me in the right direction? Or let me know if there's something technically impossible about what I am attempting?

Thanks.

Oh, also, here's a C# test case which works:

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");
    }
}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyue0225 2013-03-08 00:23
    已采纳

    Solution was two-part issue.

    Proper syntax to make the call is:

    $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));
    

    Additional issue was that the AttributeFilter class expected the property 'Value' to be of type 'object'. Changing 'Value' to be of type 'string' removed a serialization exception which was occurring.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题