Problem using Perl web service with C# client.

From: Peter Conrey (pfconrey_at_hotmail.com)
Date: 09/01/04


Date: 1 Sep 2004 10:18:44 -0700

I have a perl web service (using SOAP::Lite) with a method called
"Detail" that returns a strucure (hash reference to be exact). It
works fine when consumed by a Perl client, but when I try to consume
it with a C# application, I get the following runtime error from C#:

  Cannot assign object of type System.Xml.XmlNode[] to an object of
type ConsoleApplication1.com.hilton.crmdev.SummaryType.

Below is the Perl code that generates the hash, the.wsdl file, the
returned SOAP message and the C# client code. Sorry for the long post.
Any help would be greatly appreciated.

#######################################################
### The Perl
package Test;

use strict;
use SOAP::Lite;

$SOAP::Constants::DO_NOT_USE_CHARSET = 1;

sub Detail
{
  my $class = shift();
  my $id = shift();
  my $return = {
                 ID => $id,
                 LastName => 'Conrey',
                 FirstName => 'Peter',
                 MiddleInit => 'F',
                 Title => 'Mr.'
               };
  return SOAP::Data->name( 'SummaryType' )
                   ->uri( "urn:Test" )
                   ->value( $return );
}

############################################
### The WSDL file
<?xml version="1.0"?>

<definitions name="Test"
             targetNamespace="urn:Test"
             xmlns:tns="urn:Test"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
             xmlns="http://schemas.xmlsoap.org/wsdl/">

  <types>

    <xsd:schema targetNamespace="urn:Test">

      <xsd:complexType name="SummaryType">
        <xsd:all>
          <xsd:element name="ID" type="xsd:int"
minOccurs="1" />
          <xsd:element name="LastName" type="xsd:string"
minOccurs="1" />
          <xsd:element name="FirstName" type="xsd:string"
minOccurs="1" />
          <xsd:element name="MiddleInit" type="xsd:string"
minOccurs="1" />
          <xsd:element name="Title" type="xsd:string"
minOccurs="1" />
        </xsd:all>
      </xsd:complexType>

    </xsd:schema>

  </types>

  <message name="DetailRequest">
    <part name="id" type="xsd:int"/>
  </message>

  <message name="DetailResponse">
    <part name="return" type="tns:SummaryType" />
  </message>

  <portType name="TestDetailPort">
    <operation name="Detail">
      <input message="tns:DetailRequest"/>
      <output message="tns:DetailResponse"/>
    </operation>
  </portType>

  <binding name="TestDetailBinding" type="tns:TestDetailPort">
    <soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="Detail">
      <soap:operation soapAction="urn:Test#Detail"/>
      <input>
        <soap:body use="encoded" namespace="urn:Test"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded" namespace="urn:Test"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>

  <service name="TestDetailService">
    <port name="TestDetailPort" binding="tns:TestDetailBinding">
      <soap:address location="http://crmdev.hilton.com:7994/webservices/test/Test.pl"/>
    </port>
  </service>

</definitions>

################################################
### The SOAP Response message
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:namesp3="http://xml.apache.org/xml-soap"
                   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
                   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <SOAP-ENV:Body>
    <namesp1:DetailResponse xmlns:namesp1="urn:Test">
      <namesp2:SummaryType xmlns:namesp2="urn:Test"
xsi:type="namesp3:SOAPStruct">
        <FirstName xsi:type="xsd:string">Peter</FirstName>
        <Title xsi:type="xsd:string">Mr.</Title>
        <ID xsi:type="xsd:int">60441557</ID>
        <MiddleInit xsi:type="xsd:string">F</MiddleInit>
        <LastName xsi:type="xsd:string">Conrey</LastName>
      </namesp2:SummaryType>
    </namesp1:DetailResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

################################################
### The C# client
using System;
using System.Xml;
using System.Collections;

namespace ConsoleApplication1
{
        class Class1
        {
                [STAThread]
                static void Main(string[] args)
                {
                        com.hilton.crmdev.TestDetailService ds = new
com.hilton.crmdev.TestDetailService();
                        com.hilton.crmdev.SummaryType sumType = ds.Detail(60441557);
                        Console.WriteLine( "got it" );
                        Console.WriteLine( "{0} {1} {2} {3}",
                                           sumType.Title,
                                           sumType.FirstName,
                                           sumType.MiddleInit,
                                           sumType.LastName );
                        Console.ReadLine();
                }
        }
}

#######################################################
### The auto-generated C# proxy class
namespace ConsoleApplication1.com.hilton.crmdev {
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System;
    using System.Web.Services.Protocols;
    using System.ComponentModel;
    using System.Web.Services;
    
    
    /// <remarks/>
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="TestDetailBinding",
Namespace="urn:Test")]
    public class TestDetailService :
System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        /// <remarks/>
        public TestDetailService() {
            this.Url =
"http://crmdev.hilton.com:7994/webservices/test/Test.pl";
        }
        
        /// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("urn:Test#Detail",
RequestNamespace="urn:Test", ResponseNamespace="urn:Test")]
        [return: System.Xml.Serialization.SoapElementAttribute("return")]
        public SummaryType Detail(int guest_id) {
            object[] results = this.Invoke("Detail", new object[]
{guest_id});
            return ((SummaryType)(results[0]));
        }
        
        /// <remarks/>
        public System.IAsyncResult BeginDetail(int guest_id,
System.AsyncCallback callback, object asyncState) {
            return this.BeginInvoke("Detail", new object[] {guest_id},
callback, asyncState);
        }
        
        /// <remarks/>
        public SummaryType EndDetail(System.IAsyncResult asyncResult)
{
            object[] results = this.EndInvoke(asyncResult);
            return ((SummaryType)(results[0]));
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.SoapTypeAttribute("SummaryType",
"urn:Test")]
    public class SummaryType {
        
        /// <remarks/>
        public int GuestID;
        
        /// <remarks/>
        public string LastName;
        
        /// <remarks/>
        public string FirstName;
        
        /// <remarks/>
        public string MiddleInit;
        
        /// <remarks/>
        public string Title;
    }
}



Relevant Pages

  • .NET Web Service Consumer Incorrectly Handling UTF-8 Data
    ... We are using a .NET client to consume a web service written in Perl in ... Other client system, written in Java and Perl, ... are not having any issues consuming this web service. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: C# needing to consume perl/SOAP::Lite service
    ... I need to consume from a C#. ... The classes in perl are pretty simple, ... each taking a string and returning a string (ranging from 1 bytes, ... The problem is I don't have a WSDL interface, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: accessor problem in OO
    ... yes, if $ref_hash is a hash reference, you get the value associated to the ... is part of an array is no more relevant. ... Does this what Perl really sees: ... You call the namemethod of your object $obj (I call ...
    (perl.beginners)
  • Re: XML::Simple Problem
    ... I am somewhat of a newbie at perl so I do nto know how to check if the ... convert the hash reference into useable perl variables you can ... If foo turns out to be a list reference and you want element 2 of the list, ... If foo turns out to be a hash reference and you want element bar, ...
    (comp.lang.perl.modules)
  • Re: run cron every four weeks?
    ... Using perl in a situation like this would consume far more ... >resources than a bash script, ... You're suffering from premature optimization. ...
    (comp.sys.hp.hpux)