473,854 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connecting to a WCF Service hosted in a Windows Service

I have written a simple WCF service hosted in a Windows console application
and a simple WCF client console application that connects successfully to
that service and retrieves data. I then ported the console application to
WinForms and also got that to work properly.

My next move was to host the WCF service in a Windows service application. I
believe I have that working correctly, but I can't for the life of me get a
client to connect to the service. I did not use svcutil to generate proxy
code for the client, but instead relied on using a ChannelFactory to
instantiate my client connection to the service.

Here's the client code:

namespace MyClient
{
public partial class MainForm : Form
{
private IMyService service;

public MainForm()
{
InitializeCompo nent();

try
{
ChannelFactory< IMyServicefacto ry = new
ChannelFactory< IMyService>("My Service");
service = factory.CreateC hannel();
string myData = service.GetMyDa ta();
MessageBox.Show (myData);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message + ex.StackTrace);
}
}
}
}

Here's the client app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.service Model>
<client>
<endpoint address="net.tc p://localhost:12345/MyService/service"
binding="netTcp Binding"
contract="Contr acts.IMyService "
name="MyService ">
</endpoint>
</client>
</system.serviceM odel>
</configuration>

Here's the server app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.service Model>
<services>
<service name="MyService ">
<host>
<baseAddresse s>
<add
baseAddress="ne t.tcp://localhost:12345/MyService/service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcp Binding"
contract="Contr acts.IMyService ">
</endpoint>
<endpoint address="mex"
binding="mexTcp Binding"
contract="IMeta dataExchange">
</endpoint>
</service>
</services>
</system.serviceM odel>
<behaviors>
<serviceBehavio rs>
<behavior name="metadataS upport">
<serviceMetadat a>
</serviceMetadata >
</behavior>
</serviceBehavior s>
</behaviors>
</configuration>

Here's the contract code:

namespace Contracts
{
[ServiceContract]
public interface IMyService
{
[OperationContra ct]
string GetMyData();
}
}

I get the following exception when invoking the service.GetMyDa ta() method:

Could not connect to net.tcp://localhost:12345/MyService/service. The
connection attempt lasted for a time span of 00:00:00.984381 3. TCP error code
10061: No connection could be made because the target machine actively
refused it.
Server stack trace:
at System.ServiceM odel.Channels.S ocketConnection Initiator.Conne ct(Uri
uri, TimeSpan timeout)
at System.ServiceM odel.Channels.B ufferedConnecti onInitiator.Con nect(Uri
uri, TimeSpan timeout)
at
System.ServiceM odel.Channels.C onnectionPoolHe lper.EstablishC onnection(TimeS pan timeout)
at
System.ServiceM odel.Channels.C lientFramingDup lexSessionChann el.OnOpen(TimeS pan timeout)
at System.ServiceM odel.Channels.C ommunicationObj ect.Open(TimeSp an timeout)
at System.ServiceM odel.Channels.S erviceChannel.O nOpen(TimeSpan timeout)
at System.ServiceM odel.Channels.C ommunicationObj ect.Open(TimeSp an timeout)
at
System.ServiceM odel.Channels.S erviceChannel.C allOpenOnce.Sys tem.ServiceMode l.Channels.Serv iceChannel.ICal lOnce.Call(Serv iceChannel
channel, TimeSpan timeout)
at
System.ServiceM odel.Channels.S erviceChannel.C allOnceManager. CallOnce(TimeSp an
timeout, CallOnceManager cascade)
at System.ServiceM odel.Channels.S erviceChannel.E nsureOpened(Tim eSpan
timeout)
at System.ServiceM odel.Channels.S erviceChannel.C all(String action,
Boolean oneway, ProxyOperationR untime operation, Object[] ins, Object[] outs,
TimeSpan timeout)
at System.ServiceM odel.Channels.S erviceChannel.C all(String action,
Boolean oneway, ProxyOperationR untime operation, Object[] ins, Object[] outs)
at
System.ServiceM odel.Channels.S erviceChannelPr oxy.InvokeServi ce(IMethodCallM essage methodCall, ProxyOperationR untime operation)
at System.ServiceM odel.Channels.S erviceChannelPr oxy.Invoke(IMes sage
message)

Exception rethrown at [0]:
at System.Runtime. Remoting.Proxie s.RealProxy.Han dleReturnMessag e(IMessage
reqMsg, IMessage retMsg)
at System.Runtime. Remoting.Proxie s.RealProxy.Pri vateInvoke(Mess ageData&
msgData, Int32 type)
at Contracts.IMySe rvice.GetMyData ()
at WinClient.MainF orm.GetMyData() in C:\Documents and Settings\adrian \My
Documents\Visua l Studio 2005\Projects\W CFTest\WinClien t\MainForm.cs:l ine 54

This is my first attempt at using WCF. Any help would be greatly appreciated.
Mar 19 '07 #1
0 8282

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3664
by: Matt | last post by:
I know it is possible to establish a connection to an SQL Server over the Internet via Enterprise Manager. My question is, how secure is this connection? Is there a best practices document for this type of connection? Here is my scenario: We are looking to outsource our web hosting. Currently, we upload client sensitive data to our SQL Server databases within our internal network. If we outsource, the SQL server will be on a different
2
7283
by: Fadi | last post by:
Backround: I am trying to figure out how to do the equivalant of a classic COM Local Server Singleton in .NET/C#. I created a coupld of simple Class Libs that exposes public interfaces and hosted them in a Windows Forms EXE. Create a Windows Forms client and both the Client and the Host EXEs configure the remoting protocols through respective .config files. Problem: I want to change the host from an Win Forms EXE to a Windows Service.
8
2464
by: Julia | last post by:
Hi, My client uses a remote object when I host the remote object inside a windows application all seem to work fine but when I host the same object inside a windows service I get the following error " connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because
3
3753
by: GTDriver | last post by:
I'm trying to connect my application with a web service located on my own web server(localhost). I guess when the solution/proect is built it makes a file called 'Web References\localhost\References.vb' In this file a line of code reports the following error: Line of code: Dim results() As Object = Me.Invoke("GetCustomers", New Object() {Country})
3
3423
by: Big Charles | last post by:
Hi, We have developed an ASP.NET web application and are planning to host it in an external Server, which provides us a good bandwidht. We need to put he web application outside because the bandwidtht that we have in our local office won't be enough for the number of users that access to our web app. But for backup issues, the database server will be in our local office.
1
6440
by: Karch | last post by:
I am writing a WCF Service using MSMQ hosted in a Windows Service on Windows XP. All the required components are installed (.NET3, MSMQ, etc). For some reason my service tries to start and then stops right away. I have looked at everything and can't see anything wrong - in fact, I started this a few weeks ago and I swear it was running at one point. I have included the app.config and service code below - any idea why my service will...
10
15964
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END 60003/tcp
5
5592
by: Oriane | last post by:
Hi, I have a .Net Visual Studio solution with one asp.net Web application, which uses a Asp.Net Web service. Both are compiled in debug mode, and both are using the Studio development web server for debugging. I have also add the Web reference to the web service with the "Add Web service in the solution" choice, that is the Web app starts the Web service with the Studio development web server. So I thought I could set breakpoints on...
0
5727
by: khurramlone | last post by:
I am trying to generate a client proxy from a WCF service library. I am using VS2005, .NET 3.0 on a Windows XP Pro workstation. The WCF service is hosted in a windows service. When I run the windows service as a console application, there are no problems. I can run svcutil.exe against that address and it generates the proxy. However, when I compile that service in release mode, and install it on the workstation using InstallUtil, I get an error...
0
11025
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10682
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9513
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4562
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3187
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.