What is an XmlNode?
I am trying to submit data to a web service using PHP and nusoap. The web service operation I'm calling is located here: http://service.leads360.com/ClientService.asmx?op=AddLeads
The operation's expected parameters are username
as string, password
as string, and leads
as XmlNode. For this XmlNode they give examples of the schema and xml doc:
http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd
http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml
So I copied the xml doc they gave and turned it into an array, put that array inside another array called $params
along with username
and password
and executed
$result = $client->call('AddLeads', $params);
Unfortunately it is giving me the following error:
[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 ---
I pasted my code at: http://pastebin.com/7jbPGuqn.
I am also pasting the array I am passing as the leads parameter below. Please tell me if the array represents the xml doc in the example and if it is a valid 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
)
)
)
)
)
)
)
Unlike an element who's value is something simple as an int or string, an XmlNode
is a more complex structure, it is an XML element.
Inside the WSDL of the service you will find the following for the AddLeads
element:
<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>
This is the schema for the AddLeads
element. The schema will be used to validate the markup you provide.
Notice that username
and password
have the type string, while leads
is "any" complex type. That will mean a message like this one:
<soapenv:Body>
<AddLeads>
<username>foo</username>
<password>bar</password>
<leads>
You may enter ANY elements at this point
</leads>
</AddLeads>
</soapenv:Body>
But "any" complex type is a little bit to wide as a definition, so the creators of the web service decided to limit it to something they recognize as useful information. The following schema limits the "any" in the context of the AddLeads
operation:
http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd
for which the following is a valid instance:
http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml
I don't know PHP but your code must generate a message that respects the web service WSDL types an the leads
type.
I suggest you use a tool like SoapUI to create requests to call the web service. Once you get a valid message content with a successful response, adapt your PHP code to generate the same format. You will also find (another tool) the TCP Monitor very useful in seeing what messages get exchanged between your client and the web service.
精彩评论