我有一个非常简单的c#应用程序,运行WCF服务如下:
[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>
因为我并不真正理解PERL我从网上拿了一个客户端示例并对其进行了一些定制:
#!/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" );
}
运行时收到以下错误消息:
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 ****
我错过了什么?
perl应该调用c#server中的SendMessage(“some text”)方法......