2011-08-18 164 views
0

我正在尝试使用PHP和nusoap将数据提交到Web服务。我打电话Web服务操作位于:http://service.leads360.com/ClientService.asmx?op=AddLeads什么是XmlNode?

操作的预期参数username字符串,password字符串,并作为leads XmlNode的。对于此的XmlNode他们给出的架构和XML文档的例子:

http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd

http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml

所以我复制他们给了XML文档,并把它变成一个数组,把该数组内的另一个数组称为$params随着usernamepassword和执行

$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] => [email protected] 
               ) 
              [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] => [email protected] 
               ) 
              [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] => [email protected] 
               ) 
              [3] => Array 
               (
               ) 
              [3_attr] => Array 
               (
                [FieldId] => -9999999 
                [Value] => 333333333 
               ) 
             ) 
           ) 
         ) 
       ) 
     ) 
) 

回答

0

不像谁是值的元素是简单的东西作为一个int或字符串,XmlNode是一个更复杂的结构,它是一个XML元素。

,你会发现在AddLeads元以下的服务的WSDL内部:

<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元素的模式。该模式将用于验证您提供的标记。

注意usernamepassword有string类型,而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操作的上下文:

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服务之间交换的消息时非常有用。