1

I'm having very simple c# application which running WCF service as follows:

[ServiceContract]
public interface IMessageRepository
{
    event EventHandler<string> OnNewMessage;

    [OperationContract]
    void RegisterClient();

    [OperationContract]
    void SendMessage(string message);

    void ClearClients();
}

App.config

<system.serviceModel>
  <services>
    <service name="CatcherService.Services.MessageRepository">
      <host>
        <baseAddresses>
          <add baseAddress = "http://localhost:8740/MessageRepository/" />
        </baseAddresses>
      </host>
      <endpoint address=""
                binding="basicHttpBinding"
                contract="CatcherService.Infrastructure.IMessageRepository"
            >
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange"
            />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8740/MessageRepository/"/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

since i don't really understand PERL i took a client example from web and customized it a bit:

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
use SOAP::Lite +trace => [ transport => sub {
    my ($in) = @_;
    if ( ref($in) eq "HTTP::Request") {
        print( "**** REQUEST ****\n" . $in->content() . "\n**** END REQUEST ****\n" );
    } 
    elsif ( ref($in) eq "HTTP::Response") {
        print( "**** RESPONSE ****\n" . $in->content() . "\n**** END RESPONSE ****\n" );
    }
} ];

my $port = 8740;
my $server = "http://localhost:$port";
my $namespace = 'http://tempuri.org/';

# Setup Network Connection
my $service = SOAP::Lite
    ->ns( $namespace, 'my' )
    ->proxy( $server )
    ->on_action( sub { 
        my $action = sprintf( 'IMessageRepository/%s', @_ );
        print( "action: '$action'\n" ); 
        return $action;
    } );

print( Dumper( $service ) );

eval {
    print( "making request\n" );
    my $response = $service->SendMessage("A message from perl client");
    print( "got response:\n$response\n" );
};
if ( $@ ) {
    print( "failed:\n**************************\n$@\n*****************************\n" );
}

i'm getting the following error message when running:

action: 'IMessageRepository/http://tempuri.org/'
**** REQUEST ****
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:my="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><my:SendMessage><c-gensym3 xsi:type="xsd:string">A message from perl client</c-gensym3></my:SendMessage></soap:Body></soap:Envelope>
**** END REQUEST ****
**** RESPONSE ****
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<HTML><HEAD><TITLE>Not Found</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>

<BODY><h2>Not Found</h2>

<hr><p>HTTP Error 404. The requested resource is not found.</p>

</BODY></HTML>


**** END RESPONSE ****

what am i missing ? the perl should call SendMessage("some text") method which in the c# server...

kaycee
  • 1,199
  • 4
  • 24
  • 42
  • I think the `action` is wrong. Try removing the `return $action` from the `on_action` handler. – simbabque Jan 25 '14 at 11:43
  • Do you have control over the server so you can look at the incoming connection? The error message says it's trying to access something that is not there. Probably that is a simple mistake. Look the complete communication including HTTP headers either on server or client side. I guess server is easier. It's a 404, so it must be because the URL is wrong. – simbabque Jan 25 '14 at 13:49
  • this is exactly what i'm trying to figure out... a demo client also in c# works good with the server configuration. this is something i'm doing wrong in the perl code i guess. – kaycee Jan 25 '14 at 14:03
  • Does it work with hand-tailored requests from Soap UI? – simbabque Jan 25 '14 at 14:19
  • Different approach. A quick google for `perl output request soap::lite` gave me http://www.perlmonks.org/?node_id=539970 which says you need to do `use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];` instead of `use SOAP::Lite;`. – simbabque Jan 25 '14 at 14:23

0 Answers0