8 Replies - 523 Views - Last Post: 26 December 2012 - 01:30 PM Rate Topic: -----

#1 fabian5003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 12

WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 06:59 AM

Hello everyone,

I'm getting the following error when I try to build the body section of a XML Document

            Dim WSHE As HeaderDTO = New HeaderDTO()
            Dim petitionWS As RequestCreateReceiptDTO = New RequestCreateReceiptDTO()
            petitionWS.Header = WSHE
            petitionWS.Header.Fecha = DateTime.UtcNow
            petitionWS.Header.Hora = DateTime.UtcNow.ToShortTimeString
            petitionWS.Header.Usuario = "oraclell"

            Dim bodyXML As DocumentReceiptServiceDTO = New DocumentReceiptServiceDTO ()
            bodyXML.CompanyId = "986799"

            peticionWS.DocumentReceiptServiceDTO = bodyXML



At the last line I'm getting the error:
Value of type WSReference.DocumentReceiptServiceDTO cannot be converted to '1-dimensional array of WSReference.DocumentReceiptServiceDTO'.



If you guys need anyother info, I'll be glad to add it. The header is successfully built but the body fails.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: WSReference.Class cannot be converted to '1-dimensional array of..

#2 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 08:57 AM

View Postfabian5003, on 26 December 2012 - 06:59 AM, said:

Hello everyone,

I'm getting the following error when I try to build the body section of a XML Document

            Dim WSHE As HeaderDTO = New HeaderDTO()
            Dim petitionWS As RequestCreateReceiptDTO = New RequestCreateReceiptDTO()
            petitionWS.Header = WSHE
            petitionWS.Header.Fecha = DateTime.UtcNow
            petitionWS.Header.Hora = DateTime.UtcNow.ToShortTimeString
            petitionWS.Header.Usuario = "oraclell"

            Dim bodyXML As DocumentReceiptServiceDTO = New DocumentReceiptServiceDTO ()
            bodyXML.CompanyId = "986799"

            peticionWS.DocumentReceiptServiceDTO = bodyXML



At the last line I'm getting the error:
Value of type WSReference.DocumentReceiptServiceDTO cannot be converted to '1-dimensional array of WSReference.DocumentReceiptServiceDTO'.



If you guys need anyother info, I'll be glad to add it. The header is successfully built but the body fails.

Thanks.


You've spelled "petition" differently on lines 2 and 11. Maybe that's your problem?
Was This Post Helpful? 0
  • +
  • -

#3 fabian5003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 12

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 09:06 AM

Oh, no, that's not the cause it's just the original code is in Spanish and as I created the post I did some basic translation so you guys could get a clearer view of the code.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 10:27 AM

At the last line I'm getting the error:
Value of type WSReference.DocumentReceiptServiceDTO cannot be converted to '1-dimensional array of WSReference.DocumentReceiptServiceDTO'.



Look at the error message it tells you the problem. Look at the types it mentions.
You are attempting to put a instance of WSReference.DocumentReceiptServiceDTO into parameter that expects an array of them (eg type: WSReference.DocumentReceiptServiceDTO() )
Was This Post Helpful? 0
  • +
  • -

#5 fabian5003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 12

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 12:22 PM

The new code is

            Dim bodyXML As DocumentReceiptServiceDTO() = Nothing
            bodyXML(0).CompanyId= "769879"
            peticionWS.DocumentReceiptServiceDTO = bodyXML





The line:

bodyXML(0).CompanyId= "769879"


Causes the error:
Object reference not set to an instance of an object.

Which is probably caused because the array has not been declared with an specific size. I don't really know what to do...
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,087
  • Joined: 02-July 08

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 12:49 PM

A List(Of T) is a type specific collection - like an array. The new keyword initializes the object and fixes the error.

Dim bodyXML As New List(Of DocumentReceiptServiceDTO)
Dim firstelem As New DocumentReceiptServiceDTO
firstelem.CompanyId = "769879"
bodyXML.Add(firstelem)

Was This Post Helpful? 1
  • +
  • -

#7 fabian5003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 12

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 01:10 PM

Thanks for your help, but now the first error showed up when assigning bodyXML to the class property:

            Dim bodyXML As New List(Of DocumentReceiptServiceDTO)
            Dim firstelem As New DocumentReceiptServiceDTO
            firstelem.CompanyId= "769879"
            bodyXML.Add(firstelem)
            peticionWS.DocumentReceiptServiceDTO = bodyXML '<<Error



Now the error is this:

Value of type 'System.Collections.Generic.List(Of WSReference.DocumentReceiptServiceDTO)' cannot be converted to '1-dimensional array of WSReference.DocumentReceiptServiceDTO '
Was This Post Helpful? 0
  • +
  • -

#8 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,087
  • Joined: 02-July 08

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 01:24 PM

bodyXML.ToArray()

Was This Post Helpful? 1
  • +
  • -

#9 fabian5003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-December 12

Re: WSReference.Class cannot be converted to '1-dimensional array of..

Posted 26 December 2012 - 01:30 PM

Thanks everyone for your help, and specially big thanks to _HAWK_. Your help was excellent! I apologize if my ignorance bothered you at any given moment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1