Hi,
I have developed (in VS2010 - on a machine with Windows 7) a small solution
which contains a WCF Service library and a Windows Service for hosting that WCF
service. The App.config which is in my WCF service is:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myWcfServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="2600" maxConcurrentSessions="2000" maxConcurrentInstances="3600" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="mySecureNetTcpBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
transferMode="Buffered"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="WcfServiceLibrary1.Service1"
behaviorConfiguration="myWcfServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/Service1" />
</baseAddresses>
</host>
<endpoint name="WcfServiceLibrary1.Service1"
address=""
binding="netTcpBinding"
bindingConfiguration="mySecureNetTcpBinding"
contract="WcfServiceLibrary1.IService1">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding"
bindingConfiguration=""
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Error, Critical"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\log\WCF_Errors.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>This file is also in my windows service with the same configurations.
My service code is something very simple:
File IService1.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
}
and file Service1.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
I have hosted this wcf service in my windows service in this way:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using WcfServiceLibrary1;
using System.IO;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
internal static ServiceHost myServiceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
StreamWriter sw;
try
{
if (myServiceHost != null)
myServiceHost.Close();
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
catch (Exception exc)
{
sw = new StreamWriter(@"C:\Log\Err.Txt");
sw.Write(exc.Message);
sw.Close();
}
}
protected override void OnStop()
{
StreamWriter sw;
try
{
if (myServiceHost != null)
{
myServiceHost.Close();
myServiceHost = null;
}
}
catch (Exception exc)
{
sw = new StreamWriter(@"C:\Log\Err.Txt");
sw.Write(exc.Message);
sw.Close();
}
}
}
}
I have added an Installer where I configured properties: Account:
NetworkService for serviceProcessInstaller
and StartType: Automatic for serviceInstaller.
I built the project, after that I install the windows service with
InstallUtil. After that I looked in my log file if something is wrong.
Unfortunately, I didn't find anything. Atfer that I enter in Computer Management
(I have Windows 7 and VS2010) and I started my Windows Service. After that I
looked again in my log file and in Logs from Event Viewer (from Application),
but again I didn't find anything.
Unfortunately, when I want to consume (to register) that address, I can't do
this thing. I tried with Add Service refference and after that with SvcUtil but
the result is the same.
When I want to add service address net.tcp://localhost:8001/Service1 with
Add Service Refference it appears on the screen An error (Detail) occured while
attempting to find services at 'net.tcp://localhost:8001/Service1'.
I checked the metadata addressed, but it seems that it's OK. Maybe I'm wrong
of course.
I run netstats -ap tcp and I didn't see my TCP protocol: 8001.
Please help me and tell me what it's wrong.
Sincerely Yours,
Florin G