Skip to main content
zamvil
Inspiring
January 23, 2014
Question

Send data complext to Net Webservice

  • January 23, 2014
  • 1 reply
  • 1351 views

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?



                        


This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
January 23, 2014

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.

zamvil
zamvilAuthor
Inspiring
January 28, 2014

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).

zamvil
zamvilAuthor
Inspiring
January 30, 2014

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