我有一个用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:编码:对象没有'options'属性
有人能指出我正确的方向吗?或者让我知道我在尝试什么在技术上是不可能的?
感谢。
哦,还有,这是一个有效的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");
}
}
答案 0 :(得分: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类期望属性'Value'属于'object'类型。将“Value”更改为“string”类型会删除正在发生的序列化异常。