6 Replies Latest reply on Jan 31, 2014 12:12 AM by BKBK

    Send data complext to Net Webservice

    zamvil

      Hello, I need to send array of array to Net webservice (rest) but the webservide respond the error:

       

      {"Exception":"Object reference not set to an instance of an object.","StackTrace":"

       

      I have an sample how can I send the with PHP and works but I try to send with CF code and I can not.

       

      This is the PHP

       

      $agent = array(

                          array(

                               ramoTecnico => 1,

                               codAgente => 5095

                               )

                          );

      $parameters->emissionRequest = $agent;

       

       

      My CF code:

       

           <cfset emissionRequest = {}>  

          <cfset emissionRequest.agente = []>

          <cfset emissionRequest.agente[1] = {}>

          <cfset emissionRequest.agente[1].ramoTecnico = "1">

          <cfset emissionRequest.agente[1].codAgente = "5095">

       

      or

       

        <cfscript>  

           emissionRequest = {

                               agente =[ {

                                              codTipoPoliza = "2",

                   ramoComercial = "5"

                                         }]

           };

      </cfscript>

       

      what is the correct form to send it? I already tried a lot of forms and any works.

       

      The net programmer modified the Webservice to receive a single array and I send only the struct and ir works but when enable the second array and I send array and struct not works.

       

       

      Somebody have any hint?

       

       

       

       


       


                              


        • 1. Re: Send data complext to Net Webservice
          BKBK Adobe Community Professional & MVP

          The different platforms, .NET, PHP and ColdFusion have different interpretations of what an array is. There are complications in interpretation even in ColdFusion itself.

           

          For example, although the latest versions of ColdFusion are written in Java, a ColdFusion array is not a Java array. To see this, run the following code:

           

          <cfset a=[]>

          <cfoutput>Class of a: #a.getClass().getName()#<br>

          Superclass of a: #a.getClass().getSuperclass().getName()#

          </cfoutput>

           

          In any case, in ColdFusion, an array of an array is, strictly speaking, a 2 dimensional array. It is defined as follows:

           

          <cfset a = arrayNew(2)>

          <cfset a[1][1]="ramoTecnico">

          <cfset a[1][2]="codAgente">

          <cfset a[2][1]=1>

          <cfset a[2][2]=5095>

           

          However, I doubt that that would work. As I said, this definition of array might not carry over to other platforms. You could be less strict. It is known that a ColdFusion structure translates as a complex type in the WSDL. You could therefore interprete a structure as an "associative array", which enables you to do something like

           

          <cfset emissionRequest = {}> 

          <cfset emissionRequest.agent = {}>

          <cfset emissionRequest.agent.ramoTecnico = 1>

          <cfset emissionRequest.agent.codAgente = 5095>

           

          This in fact reminds me of a previous thread in this forum, entitled "Invoke webservice with complex types". I would suggest you have a look.

          • 2. Re: Send data complext to Net Webservice
            zamvil Level 1

            Thanks BKBK.

             

             

            I already tried a lot of different ways to send the object/parameters and I can't do it.

             

            If I send the agente struct empty, it the webservice detects the array.

             

                <cfset param= structnew() >   

                <cfset param.emissionRequest = {}>

                <cfset param.emissionRequest.codSuc = "30">

                <cfset param.emissionRequest.producto = "200">

                <cfset param.emissionRequest.poliza = {}>

                <cfset param.emissionRequest.poliza.codTipoPoliza = "2">

                <cfset param.emissionRequest.poliza.ramoComercial = "5">   

                <cfset param.emissionRequest.agente = {}>

             

             

            struct
            EMISSIONREQUEST
            struct
            AGENTE
            struct [empty]
            CODSUC30
            POLIZA
            struct
            CODTIPOPOLIZA2
            RAMOCOMERCIAL5
            PRODUCTO200

            {"Exception":"Index was out of range. Must be non-negative and less than the size of the collection.Parameter name index","StackTrace":" at System.ThrowHelper.ThrowArgumentOutOfRangeExceptionExceptionArgument argument ExceptionResource resource at System.ThrowHelper.ThrowArgumentOutOfRangeException at System.Collections.Generic.List1.get_ItemInt32 index at System.Linq.Enumerable.ElementAtTSourceIEnumerable1 source Int32 index at GMXIntegrationService.EmissionService.createPolicyEmission emissionRequest in CUsersgmx.DocumentsVisual Studio 2008ProjectsGMXIntegrationServiceTestGMXIntegrationServiceEmissionService.csline 30"}

             


            but if I send values in the Agente struct display the next error

             

                <cfset param= structnew() >   

                <cfset param.emissionRequest = {}>

                <cfset param.emissionRequest.codSuc = "30">

                <cfset param.emissionRequest.producto = "200">

                <cfset param.emissionRequest.poliza = {}>

                <cfset param.emissionRequest.poliza.codTipoPoliza = "2">

                <cfset param.emissionRequest.poliza.ramoComercial = "5">   

                <cfset param.emissionRequest.agente = {}>   

                <cfset param.emissionRequest.agente.ramoTecnico = "10">

                <cfset param.emissionRequest.agente.codTipoAgente = "15">

             

             

            struct
            EMISSIONREQUEST
            struct
            AGENTE
            struct
            CODTIPOAGENTE15
            RAMOTECNICO10
            CODSUC30
            POLIZA
            struct
            CODTIPOPOLIZA2
            RAMOCOMERCIAL5
            PRODUCTO200

            {"Exception":"Object reference not set to an instance of an object.","StackTrace":" at GMXIntegrationService.EmissionService.createPolicyEmission emissionRequest in CUsersgmx.DocumentsVisual Studio 2008ProjectsGMXIntegrationServiceTestGMXIntegrationServiceEmissionService.csline 30"}

             

             

            I don't know how can I resolve this problem. I can't believe that the CF can do send complext data to Net webservice (restfull).

            • 3. Re: Send data complext to Net Webservice
              zamvil Level 1

              Any hint of this kind of object to send a NET webservice?

              • 4. Re: Send data complext to Net Webservice
                BKBK Adobe Community Professional & MVP

                With the understanding that array means an associative array in this case, then the variable param.emissionRequest.agente is a struct of a struct of a struct. That is, an array of an array of an array.

                 

                That is 3-deep. Perhaps one layer too deep. You originally wanted an array of an array. So, what happens when you call the service with

                 

                <cfset emissionRequest = {}>

                <cfset emissionRequest.codSuc = "30">

                <cfset emissionRequest.producto = "200">

                <cfset emissionRequest.poliza = {}>

                <cfset emissionRequest.poliza.codTipoPoliza = "2">

                <cfset emissionRequest.poliza.ramoComercial = "5">  

                <cfset emissionRequest.agente = {}>

                <cfset emissionRequest.agente.ramoTecnico = "10">

                <cfset emissionRequest.agente.codTipoAgente = "15">

                • 5. Re: Send data complext to Net Webservice
                  zamvil Level 1

                  Thanks so much BkBK for your support.  I found the solution in another discussion where you participated too.

                   

                  I have to send an Struct - Array - Struct.

                   

                  This is the solution:

                   

                  <cfscript>

                                           Agente = structNew();

                                           arrAgente.agente = Arraynew(1);

                                           arrAgente.agente[1] = structnew();

                                           arrAgente.agente[1].ramoTecnico = "10";

                                           arrAgente.agente[1].codTipoAgente ="15";

                                           Agente = arrAgente; 

                            </cfscript>

                   

                  And this is all the main struct

                   

                  <cfset param= structnew() >   

                      <cfset param.emissionRequest = {}>

                      <cfset param.emissionRequest.codSuc = "30">

                      <cfset param.emissionRequest.producto = "200">   

                      <cfset param.emissionRequest.poliza = {}>

                      <cfset param.emissionRequest.poliza.codTipoPoliza = "2">

                      <cfset param.emissionRequest.poliza.ramoComercial = "5">

                   

                      <cfset param.emissionRequest.agente = Agente>

                   

                   

                  struct
                  EMISSIONREQUEST
                  struct
                  AGENTE
                  struct
                  AGENTE
                  array
                  1
                  struct
                  CODTIPOAGENTE15
                  RAMOTECNICO10
                  CODSUC30
                  POLIZA
                  struct
                  CODTIPOPOLIZA2
                  RAMOCOMERCIAL5
                  PRODUCTO200
                  • 6. Re: Send data complext to Net Webservice
                    BKBK Adobe Community Professional & MVP

                    Good news! Do you mean the discussion I mentioned earlier?

                     

                    In any case, please kindly mark this question as answered. Invoking web services with complex types is a common task. Your solution will certainly help others.