0

I’m trying to call a Web service via SOAP (https://modelviewers.pilotfishtechnology.com/modelviewers/OTA/model/Format.OTA_HotelRoomListRQ.html).

My code, so far, is:

var OTA_HotelRoomListRQ = new MyMapping.OTA_HotelRoomListRQ()
{
   TimeStamp = DateTime.Now,
   Version = 1,
   HotelRoomLists = new HotelRoomListType[] { new HotelRoomListType { HotelCode = "12345" } }
 };

 MyMapping.OTA_HotelRoomListRS OTA_HotelRoomListRS = null;
 var test = MyMapping_PortTypeClient.ReadRoomTypes(securityHeaderType, ref MessageID, ref to, ref from, ref action, OTA_HotelRoomListRQ, out OTA_HotelRoomListRS);

I get the following error:

There was an error in serializing one of the headers in message ReadRoomTypesRequest: 'Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'MySolution.ReadMapping.VendorMessageType[]' to 'MySolution.ReadMapping.VendorMessageType'
error CS0030: Cannot convert type 'MySolution.ReadMapping.VendorMessageType[]' to 'MySolution.ReadMapping.VendorMessageType'
error CS0029: Cannot implicitly convert type 'MySolution.ReadMapping.VendorMessageType' to 'MySolution.ReadMapping.VendorMessageType[]'
error CS0029: Cannot implicitly convert type 'MySolution.ReadMapping.VendorMessageType' to 'MySolution.ReadMapping.VendorMessageType[]'
'.  Please see InnerException for more details.

I don’t understand what I’m missing and what the error references.

Pine Code
  • 2,466
  • 3
  • 18
  • 43

2 Answers2

0

Try 1: A known issue with WSDL.exe can cause a proxy class to be generated incorrectly if an array of complex type includes an element that's also an array of complex type and for which only one element exists.

There are three workarounds available:

  • You can generate the proxy class manually by using WSDL.exe and then change the proxy class in which the data type was inappropriately created as a two-dimensional array (for example, CustomType[][]) so that it's a single-dimensional array (for example, CustomType[]).

  • You can change the data type in the desired Web Services Description Language (WSDL) so that a second, optional element is included in the definition. You can do this by adding an element such as the following example: <xs:element minOccurs="0" name="dummyElement" nillable="true" type="xs:string"/>

  • You can change the complex type in the desired WSDL so that the boundary attributes are part of the complex type instead of being part of the element. (That is, you can move the minOccurs and maxOccurs attributes to the complex type and then remove them from the element.)

See: Unable to generate a temporary class (result=1) error when executing the Invoke Web Services object

Try 2: XML Serialisation works by generating code to perform the serialisation. This is done in a temporary assembly created for that purpose the first time it is needed.

However this relies on being able to write the assembly to disk.1

Your options are either to:

  • Given the user account which is running the process write permission (for an ASP.NET application this is likely to be a bad idea)
  • Use the SDK tool (sgen.exe) to pre-generate (at development/compile time) the serialisation assembly, and then use (and deplot) that assembly.

See: System.InvalidOperationException: Unable to generate a temporary class (result=1)

Danut Radoaica
  • 1,860
  • 13
  • 17
  • I’m using Visual Studio’s “Service References”, so I don’t make use of WSDL.exe directly. Once I added the service reference to my project, I navigated to the generated class and manually changed `VendorMessageType[][]` with `VendorMessageType[]`. Now, everything works fine. – Pine Code Nov 01 '22 at 11:54
0

The error message state Cannot convert type 'MySolution.ReadMapping.VendorMessageType[]' to 'MySolution.ReadMapping.VendorMessageType' , check that the type of the object trying to be serialize has the correct object type.

[System.Xml.Serialization.XmlArrayItemAttribute("VendorMessageType", typeof(VendorMessageType), IsNullable=false)]
public VendorMessageType[] VendorMessageType
Max
  • 794
  • 3
  • 7