我正在尝试使用PHP和nusoap将数据提交到Web服务。我正在呼叫的Web服务操作位于:http://service.leads360.com/ClientService.asmx?op=AddLeads
操作的预期参数为username
为字符串,password
为字符串,leads
为XmlNode。对于这个XmlNode,他们提供了schema和xml doc的示例:
http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd
http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml
所以我复制了他们提供的xml doc并将其转换为数组,将该数组放在另一个名为$params
的数组中,同时放入username
和password
并执行
$result = $client->call('AddLeads', $params);
不幸的是它给了我以下错误:
[faultcode] => soap:Server
[faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at LeadManager.Business.XmlHelper.RemoveNamespace(XmlNode xml, Boolean asElement) in c:\Code\DEV\LeadManager_Business\Utilities\XmlHelper.cs:line 323
at LeadManagerService.ClientService.InsertSerializedLeads(XmlNode descriptors)
at LeadManagerService.ClientService.InsertLeads(XmlNode descriptor)
at LeadManagerService.Invoker 1.Invoke(ServiceContext context, String methodName, ICredentials credentials, Object parameters, Requestor requestor)
at LeadManagerService.ClientService.AddLeads(String username, String password, XmlNode leads)
--- End of inner exception stack trace ---
我将代码粘贴到:http://pastebin.com/7jbPGuqn。
我也粘贴了我传递的数组作为下面的引导参数。请告诉我数组是否代表示例中的xml文档,以及它是否为有效的XmlNode
。
Array
(
[Leads] => Array
(
[Lead] => Array
(
[0] => Array
(
[Status] => Array
(
)
[Status_attr] => Array
(
[StatusId] => 2
)
[Campaign] => Array
(
)
[Campaign_attr] => Array
(
[CampaignId] => 3
)
[Agent] => Array
(
)
[Agent_attr] => Array
(
[AgentId] => 1
)
[Fields] => Array
(
[Field] => Array
(
[0] => Array
(
)
[1] => Array
(
)
[0_attr] => Array
(
[FieldId] => 2
[Value] => F1Name
)
[1_attr] => Array
(
[FieldId] => 3
[Value] => L1Name
)
[2] => Array
(
)
[2_attr] => Array
(
[FieldId] => 4
[Value] => a@y.com
)
[3] => Array
(
)
[3_attr] => Array
(
[FieldId] => 5
[Value] => 111111111
)
[4] => Array
(
)
[4_attr] => Array
(
[FieldId] => 6
[Value] =>
)
)
)
)
[1] => Array
(
[Fields] => Array
(
[Field] => Array
(
[0] => Array
(
)
[1] => Array
(
)
[0_attr] => Array
(
[FieldId] => 2
[Value] => F2Name
)
[1_attr] => Array
(
[FieldId] => 3
[Value] => L2Name
)
[2] => Array
(
)
[2_attr] => Array
(
[FieldId] => 4
[Value] => b@y.com
)
[3] => Array
(
)
[3_attr] => Array
(
[FieldId] => 5
[Value] => 222222222
)
)
)
)
[2] => Array
(
[Fields] => Array
(
[Field] => Array
(
[0] => Array
(
)
[1] => Array
(
)
[0_attr] => Array
(
[FieldId] => 2
[Value] => F3Name
)
[1_attr] => Array
(
[FieldId] => 3
[Value] => L3Name
)
[2] => Array
(
)
[2_attr] => Array
(
[FieldId] => 4
[Value] => c@y.com
)
[3] => Array
(
)
[3_attr] => Array
(
[FieldId] => -9999999
[Value] => 333333333
)
)
)
)
)
)
)
答案 0 :(得分:0)
与值为int或string的简单元素不同,XmlNode
是一个更复杂的结构,它是一个XML元素。
在服务的WSDL中,您将找到AddLeads
元素的以下内容:
<s:element name="AddLeads">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="leads">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
这是AddLeads
元素的架构。该架构将用于验证您提供的标记。
请注意,username
和password
具有类型字符串,而leads
是“任何”复杂类型。这意味着像这样的消息:
<soapenv:Body>
<AddLeads>
<username>foo</username>
<password>bar</password>
<leads>
You may enter ANY elements at this point
</leads>
</AddLeads>
</soapenv:Body>
但是“任何”复杂类型作为定义都有点宽泛,因此Web服务的创建者决定将其限制为他们认为有用的信息。以下模式限制了AddLeads
操作的上下文中的“any”:
http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd
以下是有效的实例:
http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml
我不知道PHP,但您的代码必须生成一个消息,该消息尊重Web服务WSDL类型leads
类型。
我建议您使用SoapUI之类的工具来创建调用Web服务的请求。获得成功响应的有效消息内容后,请调整PHP代码以生成相同的格式。您还会发现TCP Monitor(另一个工具)非常有用,可以查看客户端与Web服务之间交换的消息。