5 Replies Latest reply on Dec 9, 2013 7:08 PM by zamvil

    Invoke NET webservice(svc) with data complext

    zamvil Level 1

      I'm trying to invoke a NET webservice type REST but I have problems because first, I have to get the values and send like a object.

       

      I put the values in structs but someones I have to puthem in a list, I think so. The NET developers send me a sample of how can I invoke in net and this code Im trying to translate in CF.

       

      This is NET Code

       

      protected void Button1_Click(object sender, EventArgs e)

          {

              //Create Emission object in order to manage entities for emission process

              IntegrationService.Emission myEmission = new IntegrationService.Emission();

              myEmission.codSuc = 30;

              myEmission.codRamo = 200;

              myEmission.poliza = new IntegrationService.Poliza() {

                                                                    //These must be initialized from WS

                                                                    numPol = "0",

                                                                    anioEndoso = 0,

                                                                    numEndoso = "0",

                                                                    //

                                                                    codMoneda = 0,

                                                                    codTipoPoliza = 4,

                                                                    fecVigDesde = new DateTime(2013,11,30),

                                                                    fecVigHasta = new DateTime(2014,11,30)

                                                                  };

              myEmission.agente = new IntegrationService.Agente() {

                                                                    codTipoAgente = 1,

                                                                    codAgente = 1000

                                                                  };

              myEmission.cliente = new System.Collections.Generic.List<IntegrationService.Cliente>(){

                                                  new IntegrationService.Cliente()

                                                  {

                                                      apPat = "Morales",

                                                      apMat = "Ibarra",

                                                      nombre = "Osiris",

                                                      tipoPersona = "J",

                                                      codItem = 0

                                                  }

                                                };

              myEmission.cobertura = new System.Collections.Generic.List<IntegrationService.Cobertura>(){

                                                      new IntegrationService.Cobertura()

                                                      {

                                                          codItem = 12,

                                                          codIndCob = 999,

                                                          codRamo = 5,

                                                          codTarifa = "13",

                                                          codObjeto = "999"

                                                      }

                                                  };

              myEmission.inciso = new System.Collections.Generic.List<IntegrationService.Inciso>(){

                                                      new IntegrationService.Inciso()

                                                      {

                                                          codItem = 0,

                                                          codIndCob = 77

                                                      }

                                                  };

              myEmission.clausula = new System.Collections.Generic.List<IntegrationService.Clausula>(){

                                                      new IntegrationService.Clausula()

                                                      {

                                                          codTipoAnexo = 25,

                                                          codAnexo = 50

                                                      }

                                                  };

              myEmission.cuota = new System.Collections.Generic.List<IntegrationService.Cuota>(){

                                                      new IntegrationService.Cuota()

                                                      {

                                                          numCuota = 6,

                                                          codItem = 5,

                                                          fecVenc = new DateTime(2013,12,31),

                                                          impPrimaMe = 440.44m,

                                                          impIvaMe = 33.33m,

                                                          impRecFinMe = 22m,

                                                          impDerPoliza = 11m,

                                                          impDerPolizaTur = 0m,

                                                          impPremio = 1010m

                                                      }

                                                  };

              myEmission.observacion = new System.Collections.Generic.List<IntegrationService.Observacion>(){

                                                      new IntegrationService.Observacion()

                                                      {

                                                          codItem = 7

                                                      }

                                                  };

              //Instantiate service as client

             

              IntegrationService.EmissionServiceClient myServiceClient = new IntegrationService.EmissionServiceClient();

              //Open service client request

              myServiceClient.Open();

              //Call specified WebMethod as necessary, sending Emission object as parameter

              result = myServiceClient.createPolicy(myEmission);

              //Close service client request

              myServiceClient.Close();

             

              Label1.Text = result;

          }

       

       

      An this is my code in CF

       

       

      <cfset myEmission = StructNew()>

      <cfset myEmission.Emission.codSuc = "30">

      <cfset myEmission.Emission.codRamo = "200">

      <cfset myEmission.Poliza.numPol = "0">

      <cfset myEmission.Poliza.anioEndoso = "0">

      <cfset myEmission.Poliza.numEndoso = "0">

      <cfset myEmission.Poliza.codMoneda = "0">

      <cfset myEmission.Poliza.codTipoPoliza = "4">

      <cfset myEmission.Poliza.fecVigDesde = "30/11/2013">

      <cfset myEmission.Poliza.fecVigHasta = "30/11/2014">

      <cfset myEmission.agente.codTipoAgente = "1">

      <cfset myEmission.agente.codAgente = "1000">

       

       

      <cfset myEmission.Cliente.apPat = "Zamora">

      <cfset myEmission.Cliente.apMat = "Villasana">

      <cfset myEmission.Cliente.nombre = "Moises">

      <cfset myEmission.Cliente.tipoPersona = "J">

      <cfset myEmission.Cliente.tipoPersona = "0">

       

       

      <cfset myEmission.Cobertura.codItem = "12">

      <cfset myEmission.Cobertura.codIndCob = "999">

      <cfset myEmission.Cobertura.codRamo = "5">

      <cfset myEmission.Cobertura.codTarifa = "13">

      <cfset myEmission.Cobertura.codObjeto = "999">

       

       

      <cfset myEmission.Inciso.codItem = "0">

      <cfset myEmission.Inciso.codIndCob = "77">

       

       

      <cfset myEmission.Clausula.codTipoAnexo = "25">

      <cfset myEmission.Clausula.codAnexo = "50">

       

       

      <cfset myEmission.Cuota.numCuota = "6">

      <cfset myEmission.Cuota.codItem = "5">

      <cfset myEmission.Cuota.fecVenc = "31/12/2013">

      <cfset myEmission.Cuota.impPrimaMe = "440.44m">

      <cfset myEmission.Cuota.impIvaMe = "33.33m">

      <cfset myEmission.Cuota.impRecFinMe = "22m">

      <cfset myEmission.Cuota.impDerPoliza = "11m">

      <cfset myEmission.Cuota.impDerPolizaTur = "0m">

      <cfset myEmission.Cuota.impPremio = "1010m">

       

       

      <cfset myEmission.Observacion.codItem = "7">

       

       

      <cfinvoke

      webservice="http://somedomain.com/IntegrationService/EmissionService.svc?wsdl"

      method="createPolicy"

      returnvariable="aString"  argumentcollection="#myEmission#">

                <cfinvokeargument name="emissionRequest" value=""/>   

      </cfinvoke>

       

       

      <cfdump var="#aString#">

       

       

      Do you know where can I found a sample of how to send this parameters to Net webservice from CF?

      No there's much informacion about this.

       

      regards

        • 1. Re: Invoke NET webservice(svc) with data complext
          zamvil Level 1

          This part I don't know how to translate in CF, If some can help me please.

           

          myEmission.cliente = new System.Collections.Generic.List<IntegrationService.Cliente>(){

                                                      new IntegrationService.Cliente()

                                                      {

                                                          apPat = "Morales",

                                                          apMat = "Ibarra",

                                                          nombre = "Osiris",

                                                          tipoPersona = "J",

                                                          codItem = 0

                                                      }

                                                    };

           

          thanks

          • 2. Re: Invoke NET webservice(svc) with data complext
            zamvil Level 1

            any hint?

             

            I found this declaration

             

            <cfset eventList = CreateObject(".net","System.Collections.Generic.List`1") />

            • 3. Re: Invoke NET webservice(svc) with data complext
              Upen@Roul Level 1

              When first we create an Object of a Web Service i.e object of a wsdl then it registers the Web Service in ColdFusion administrator and you can find that in ColdFusion administrator and if you go to your "{cfroot}\cfusion\stubs" then you will many java class files. Using these stub class files you can make Web Service to complex object.

               

              For  detailed process please refer the below URL:

              http://www.mindfiresolutions.com/ColdfusionMaking-a-call-to-a-Web-Service-with-complex-obj ect-as-input-parameter-1228.php

              • 4. Re: Invoke NET webservice(svc) with data complext
                zamvil Level 1

                Thanks Upen.

                 

                I already found how declare, and now I have this is my code

                 

                <cfset dotnetstring = createObject(".net", "System.String", "dotNetCoreProxy.jar")>

                 

                <cfset ClienteList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>

                 

                 

                <cfset myEmission = StructNew()>

                 

                <cfset ClienteList.add("{apMat='Gregory'}")>

                <cfset ClienteList.add("{nombre='Joe'}")>

                <cfset ClienteList.add("{tipoPersona='J'}")>

                <cfset ClienteList.add("{codItem='0'}")>

                <!---<cfdump var="#ClienteList.Get_Count()#">--->

                <cfset myEmission.Cliente = ClienteList>

                 

                 

                But I'm not sure if this part is correct. I can't found  how should I set the NET list in CF.

                • 5. Re: Invoke NET webservice(svc) with data complext
                  zamvil Level 1

                  Well, I already invoked the Restful webservice but it's  return me this message "Object reference not set to an instance of an object."

                   

                  I'm not sure if it is the right way how I'm setting the all values in one struct.

                   

                  Are there someone that could correct me?

                   

                  This is my last code.

                   

                  <cfset dotnetstring = createObject(".net", "System.String", "dotNetCoreProxy.jar")>

                  <cfset ClienteList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>
                  <cfset CoberturaList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>
                  <cfset IncisoList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>
                  <cfset ClausulaList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>
                  <cfset CuotaList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>
                  <cfset ObservacionList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar").init(dotnetstring.getDotNetClass())>


                  <cfset myEmission = StructNew()>
                  <cfset myEmission.Emission.codSuc = "30">
                  <cfset myEmission.Emission.codRamo = "200">
                  <cfset myEmission.Poliza.numPol = "0">
                  <cfset myEmission.Poliza.anioEndoso = "0">
                  <cfset myEmission.Poliza.numEndoso = "0">
                  <cfset myEmission.Poliza.codMoneda = "0">
                  <cfset myEmission.Poliza.codTipoPoliza = "4">
                  <cfset myEmission.Poliza.fecVigDesde = "30/11/2013">
                  <cfset myEmission.Poliza.fecVigHasta = "30/11/2014">
                  <cfset myEmission.agente.codTipoAgente = "1">
                  <cfset myEmission.agente.codAgente = "1000">

                  <cfset ClienteList.add("{apPat='Casey'}")>
                  <cfset ClienteList.add("{apMat='Walker'}")>
                  <cfset ClienteList.add("{nombre='Tom'}")>
                  <cfset ClienteList.add("{tipoPersona='J'}")>
                  <cfset ClienteList.add("{codItem='0'}")>
                  <!---<cfdump var="#ClienteList.Get_Count()#">--->
                  <cfset myEmission.Cliente = ClienteList>

                  <cfset CoberturaList.add("{codItem=12}")>
                  <cfset CoberturaList.add("{codIndCob=999}")>
                  <cfset CoberturaList.add("{codRamo=5}")>
                  <cfset CoberturaList.add("{codTarifa=13}")>
                  <cfset CoberturaList.add("{codObjeto=999}")>
                  <cfset myEmission.Cobertura = CoberturaList>

                  <cfset IncisoList.add("{codItem=0}")>
                  <cfset IncisoList.add("{codIndCob=77}")>
                  <cfset myEmission.Inciso = IncisoList>

                  <cfset ClausulaList.add("{codTipoAnexo=25}")>
                  <cfset ClausulaList.add("{codAnexo=50}")>
                  <cfset myEmission.Clausula = ClausulaList>

                  <cfset CuotaList.add("{numCuota=6}")>
                  <cfset CuotaList.add("{codItem=5}")>
                  <cfset CuotaList.add("{fecVenc='31/12/2013'}")>
                  <cfset CuotaList.add("{impPrimaMe='440.44m'}")>
                  <cfset CuotaList.add("{impIvaMe='33.33m'}")>
                  <cfset CuotaList.add("{impRecFinMe='22m'}")>
                  <cfset CuotaList.add("{impDerPoliza='11m'}")>
                  <cfset CuotaList.add("{impDerPolizaTur='0m'}")>
                  <cfset CuotaList.add("{impPremio='1010m'}")>
                  <cfset myEmission.Cuota = CuotaList>

                  <cfset ObservacionList.add("{codItem=7}")>
                  <cfset myEmission.Observacion = ObservacionList>

                  <cfset myEmission.Observacion.codItem = "7">

                  <!---<cfdump var="#myEmission#">--->

                   

                  <cfset ws= createobject("webservice","http://somedomain.com.mx/IntegrationService/EmissionService.svc?wsdl") >

                  <cfset aString = ws.createPolicy(#myEmission#) >

                   


                  <cfdump var="#aString#">