allenmpcx has asked for the wisdom of the Perl Monks concerning the following question:

Alright, I have the following perl code:
sub getComplexObj { my $_count = 12 my $mike = { 'Count'=> SOAP::Data->new( name => 'Count', value => $_count, type => +'xsd:int' )->attr({ 'xmlns' => $MC_XMLNS }), 'test' => SOAP::Data->new( name => 'test', value => 'test string', typ +e =>'xsd:string' )->attr({ 'xmlns'=> $MC_XMLNS })}; my $foo = SOAP::Data->new( name => 'return', value =>bless{ $self ,('compObj')->attr({ 'xsi:type' => typens:'compOb +j' })} )->attr({ 'xmlns' => $MC_XMLNS }); return $foo; }
I have a WSDL file and I use that to automatically generate a C# file that uses a SOAP proxy to call this function. When I run my code, I get the following error from .NET: "Failed to access class (CS3::SOAP::ComplexObject): syntax error at CS3/SOAP/ComplexObject.pm line 13, near \"typens:\"\nCompilation failed in require at (eval 201) line 3.\n" When I change the $foo object to:
my $foo = SOAP::Data->name('return')->value(bless{ $self ,'compObj'})- +>attr({ 'xmlns' => $MC_XMLNS });
I get this error from .NET: "Cannot assign object of type System.Xml.XmlNode[] to an object of type compObj." Just for reference, my C# file looks like this:
/// /// /// foo /// [System.Web.Services.WebServiceBinding(Name="ComplexObjectPort", Names +pace="http://VALIDHTTP")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] public class ComplexObj : System.Web.Services.Protocols.SoapHttpClient +Protocol { public ComplexObj() { this.Url = "http://VALIDHTTP/co.pcgi"; } [System.Web.Services.Protocols.SoapRpcMethodAttribute("http://VALIDHTT +P#getComplexObj", RequestNamespace="http://VALIDHTTP", ResponseNamesp +ace="http://VALIDHTTP")] [return: System.Xml.Serialization.SoapElement("return")] public compObj getComplexObj() { object[] results = this.Invoke("getComplexObj", new object[]); return ((compObj)(results[0])); } public System.IAsyncResult BegingetComplexObj(System.AsyncCallback cal +lback, object asyncState) { return this.BeginInvoke("getComplexObj", new object[], callback, async +State); } public compObj EndgetComplexObj(System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); return ((compObj)(results[0])); } } /// [System.Xml.Serialization.SoapType(Namespace="http://VALID HTTP")] public class compObj { /// public int Count; /// public string test; }
Then in a main file I have:
try { ComplexObject co = new ComplexObject(); compObj comp = co.getComplexObj(); } catch( Exception e ) { richTextBox1.Text+=e.Message + "\n" + e.StackTrace; }
My ultimate goal is simply to call a function from perl that returns a complex object. ANY help would be greatly appreciated.

Replies are listed 'Best First'.
Re: perl, SOAP and C#
by Errto (Vicar) on Mar 25, 2006 at 22:52 UTC
    I can't help you with your C# code but I can tell you why you got that syntax error. It's because of this snippet right here:
    { 'xsi:type' => typens:'compObj' }
    just as the Perl compiler said. I assume what you really meant is this:
    { 'xsi:type' => 'typens:compObj' }
    which is valid Perl.
      Thanks for the help! That fixed my syntax error, but now I get the error: "Can't locate object method \"attr\" via package \"compObj\" (perhaps you forgot to load \"compObj\"?) at...." where I assign the $foo object. Any thoughts??
        There is still something a bit strange in this fragment:
        value =>bless{ $self ,('compObj')->attr({ 'xsi:type' => 'typens:compOb +j' })}
        There are two issues here. First, you're blessing, into the current package, a hash reference with a single pair in which the key is $self. This makes me a little suspicious because $self is presumably a reference of some sort so I'm not totally clear on what the bless call is supposed to do. The second thing, which is what the error is coming from, is that you're calling the attr method, not on an object, but on the string 'compObj' which makes Perl think that attr is a class method in the package 'compObj', which I suspect is not what you want. Unfortunately I don't know what exactly the result is supposed to be so I can't suggest how to change it.