473,732 Members | 2,083 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 8276

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

Similar topics

5
3660
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
7277
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
2452
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
3741
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
3416
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
6428
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
15952
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
5585
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
5713
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
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9234
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
9180
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
8186
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
6733
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...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
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
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.