Home: Perl Programming Help: Advanced:
How to communicate Perl with WCF Windows Service (TCP/IP)



PerlBeginnerCR
New User

Sep 16, 2011, 3:51 PM


Views: 3190
How to communicate Perl with WCF Windows Service (TCP/IP)

I am trying to use SOAP::Lite to talk to a WCF Windows Service, but I have been unsuccessful. Could you please tell me what I am doing wrong?

My APP.CONFIG file in C#/XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="workorder_testEntities" connectionString="metadata=res:
+//*/Database_Testing.csdl|res://*/Database_Testing.ssdl|res://*/Datab
+ase_Testing.msl;provider=System.Data.SqlClient;provider connection st
+ring=&quot;Data Source=MYSERVER-NAME,1433;Initial Catalog=MYDATABASE-
+NAME;Persist Security Info=True;User ID=wo_dbo;Password=dbo2wo;Multip
+leActiveResultSets=True&quot;" providerName="System.Data.EntityClient
+" />
</connectionStrings>
<appSettings>
<add key="DB_conn" value="Data Source=MYSERVER-NAME,1433;Initial C
+atalog=MYDATABASE-NAME;User ID=MYID;Password=MYPASSWORD;"/>
</appSettings>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning, Activit
+yTracing"
propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="De
+fault">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="W
+arning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="De
+fault">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\users\MYUSER\documents\tfs-code\app_trac
+elog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Versi
+on=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp
+">
<filter type="" />
</add>
<add initializeData="c:\users\MYUSER\documents\tfs-code\app_mess
+ages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Versi
+on=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="
+Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true">
<messageLogging logMalformedMessages="true" logMessagesAtTranspo
+rtLevel="true" />
</diagnostics>
<client>
<endpoint address="http://MYSERVER-NAME:8732/Company.Department.
+Project.WCFService.ProjectService/mex"
binding="basicHttpBinding" bindingConfiguration="" contract="C
+ompany.Department.Project.WCFService.IProjectService"
name="Company.Department.Project.WCFService.ProjectService">
<identity>
<certificateReference storeName="My" storeLocation="LocalMac
+hine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</client>
<bindings>
<basicHttpBinding>
<binding name="NewBinding1" />
</basicHttpBinding>
<netTcpBinding>
<binding name="TCPBinding" closeTimeout="23:59:59" openTimeout
+="23:59:59"
receiveTimeout="23:59:59" sendTimeout="23:59:59" maxConnecti
+ons="20">
<reliableSession inactivityTimeout="23:59:59" />
<security>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Company.Department.Project.WCFService.ProjectS
+erviceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Company.Department.Project.WCFSe
+rvice.ProjectServiceBehavior"
name="Company.Department.Project.WCFService.ProjectService">
<endpoint address="net.tcp://MYSERVER-NAME:8762/ProjectService
+"
binding="netTcpBinding" bindingConfiguration="TCPBinding" na
+me="TCPEndpoint"
contract="Company.Department.Project.WCFService.IProjectServ
+ice">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://MYSERVER-NAME:8732/Company.Departmen
+t.Project.WCFService.ProjectService/mex"
binding="basicHttpBinding" bindingConfiguration="" name="Com
+pany.Department.Project.WCFService.ProjectService"
bindingName="basicHttpBinding" contract="IMetadataExchange"
+/>
<host>
<baseAddresses>
<add baseAddress="http://MYSERVER-NAME:8732/Company.Depart
+ment.Project.WCFService.ProjectService/" />
</baseAddresses>
<timeouts closeTimeout="23:59:59" openTimeout="23:59:59" />
</host>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
[download]
And my C# Interface looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Company.Department.Project.BusinessEntities;
using Company.Department.ProjectB.BusinessLogic;
using Company.Department.ProjectB.BusinessEntities;

namespace Company.Department.Project.WCFService
{
[ServiceContract(Name = "Company.Department.Project.WCFService.Pro
+jectService", Namespace = "http://projectservice.department.company.c
+om/")]
public interface IProjectService
{
[OperationContract(Name="GetWorkOrderList")]
List<BEWorkOrder> GetWorkOrderList(string siteId);

[OperationContract(Name="GetWorkOrder")]
BEWorkOrder GetWorkOrder(string woName, string siteId);

[OperationContract(Name="ReturnStatus")]
string ReturnStatus();
}
}
[download]
And the PERL CODE I have looks like this:
#!/usr/bin/perl -w
use strict;
use SOAP::Lite;

my $url = 'http://MYSERVER-NAME:8732/Company.Department.Project.Projec
+tService.ProjectService/?wsdl';
my $uri = 'http://tempuri.org/';
my $xmlns = 'http://tempuri.org/';

# Setup Network Connection

my $soap = SOAP::Lite
-> uri($uri)
-> on_action(sub{sprintf '%sIProjectService/%s', @_})
-> proxy($url);

my $response = $soap->GetWorkOrderList(SOAP::Data->new(name=>'siteId',
+ value=>'BKK'));


if($response->fault){
die $response->faultstring;
}
else{
print $response->result;
}
[download]
The error that I get is "404 Not Found at PerlSOAPExample.pl line 17 which turns out to be "my $response = $soap->GetWorkOrderList(SOAP::Data->new(name=>'siteId', value=>'BKK'));" so it seems like the data is just not going through and being received in Perl. When I entered the URL in Chrome or IE (http://MYSERVER-NAME:8732/Company.Department.Project.ProjectService.ProjectService/?wsdl) I do get the XML page returned by the Server. What am I doing incorrectly for Perl not to be able to consume the WCF Service? Any ideas? Anyone who has successfully accomplished communication between WCF and Perl?