2011-08-18 61 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服務之間交換的消息時非常有用。