2

I'm setting up a Web Service in c# and they are calling it using perl Soap::Lite. I am trying to get the program to remove the namespace prefox, and instead, define the full namespace as an xmlns attribute in the action tag. The request generated looks like this

<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:tns="https://mynamespace.org"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <tns:myMethod>
      <name xsi:type="s:string">First Cycle</name>
      <desc xsi:type="s:string"> The Description</desc>
    </tns:myMethod>
  </soap:Body>
</soap:Envelope>

The code that generated the request above is this

use strict ;
use warnings ;

use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];;

my $ns = "https://mynamespace.org";

my $HOST = "http://localhost:54387/WebService.asmx";

my $wsdl = "http://localhost:54387/WebService.asmx?wsdl";

my $soap = SOAP::Lite->service($wsdl);
$soap->default_ns($ns);

 my $som = $soap->myMethod(
     'First Cycle', 'The Description'
);

 die $som->fault->{ faultstring } if ($som->fault);
 print $som->result, "\n";

The parameters in the above show null in the web service because C# parses the parameters as being in different namespaces. instead of the prefix, I'd like the action to look like this

<myMethod xmlns="https://mynamespace.org">

I've tried using my $soap = SOAP::Lite->new( proxy => $HOST);

instead of the service description. It works but the paramters are changes to something like this <c-sysgen3 xsi:type="s:string"><c-sysgen3>

I want the request to look like this

<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:tns="https://mynamespace.org"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <myMethod xmlns="https://mynamespace.org">
      <name xsi:type="s:string">First Cycle</name>
      <desc xsi:type="s:string"> The Description</desc>
    </myMethod>
  </soap:Body>
</soap:Envelope>

or like this

<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:tns="https://mynamespace.org"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <tns:myMethod>
      <tns:name xsi:type="s:string">First Cycle</tns:name>
      <tns:desc xsi:type="s:string"> The Description</tns:desc>
    </tns:myMethod>
  </soap:Body>
</soap:Envelope>

I should mention I am not allowed to explicitly define the element tags in perl e.g.

$soap->call('myMethod',
     SOAP::Data->name('name')->value( 'First Cycle' ),
    SOAP::Data->name('desc')->value('The Description') );

Please Help (-:

Edit: My version of perl is 5.28.1 and the version of SOAP::Lite is 1.27 I.m also using .net framework 4.5

Edit: I should probably add my web service implementation

  namespace WebService
{ 

  [WebService(Namespace = "https://mynamespace.org")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [System.ComponentModel.ToolboxItem(false)]
    public class SoapService : System.Web.Services.WebService
    {

        [WebMethod]
        public string myMethod(string name, string desc)
        {
            // Implementation here
        }
    }

}
Kenny Togunloju
  • 179
  • 1
  • 7
  • One would imagine this needs to be specified where `name` and `desc` are specified. (In the WSDL?) Without something I can run, this is the extent of the help I can give. – ikegami Jun 13 '19 at 04:54
  • Strange - per the [docs](https://metacpan.org/pod/SOAP::Lite#default_ns($uri)), the `default_ns` call should have done that. Are you running a version of the code that includes that call? I have sometimes accidentally commented out important things while trying to nail down a slippery bug :) . **Edit** You could also try `$soap->use_prefix(false)` per [docs](https://metacpan.org/pod/SOAP::Lite#use_prefix(boolean)). – cxw Jun 13 '19 at 13:36
  • Would you please edit your question to specify the versions of Perl and of SOAP::Lite? – cxw Jun 13 '19 at 13:37
  • @cxw I added the versions. Also, I am running a version of he code that does that call. I tried use_prefix too but it still doesn't work. – Kenny Togunloju Jun 14 '19 at 15:36

1 Answers1

1

As per your requirement you can use register_ns method provided by SOAP::Serializer class

register_ns : The register_ns subroutine allows users to register a global namespace with the SOAP Envelope. The first parameter is the namespace, the second parameter to this subroutine is an optional prefix. If a prefix is not provided, one will be generated automatically for you. All namespaces registered with the serializer get declared in the <soap:Envelope /> element.

As per your code need to add these line (for sample, register few namespace parameter)

my $ns = "https://mynamespace.org";
my $HOST = "http://localhost:54387/WebService.asmx";
my $wsdl = "http://localhost:54387/WebService.asmx?wsdl";

my $soap = SOAP::Lite->service($wsdl);
#============#
$soap->serializer->register_ns('http://microsoft.com/wsdl/mime/textMatching/','tm');
$soap->serializer->register_ns('http://schemas.xmlsoap.org/wsdl/soap12/','soap12');
$soap->serializer->register_ns('urn:com:ssn:schema:service:v2.7:BasicTypes.xsd','urn3');
$soap->default_ns($ns);
# Gets or sets the prefix that labels the SOAP envelope namespace. This defaults to SOAP-ENV.
$soap->envprefix('SOAP-ENV');
#====#

Please check https://metacpan.org/dist/SOAP-Lite/view/lib/SOAP/Serializer.pod

amit bhosale
  • 482
  • 4
  • 9