Note that there are some explanatory texts on larger screens.

plurals
  1. POHosting a WCF service as a WindowsService?
    primarykey
    data
    text
    <p>Can anyone tell me the method to host a WCF service Library as a windows service? I have tried to follow various links but always get some or the other error. Either the service starts and stops immediately or the client is unable to access the service hosted on windows..I am using simple WPF app as a client.</p> <p>Also can anyone tell me difference between the end point address and the base address and what should be there set to while hosting WCF as Windows Service</p> <p>App.config for WCF service</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;connectionStrings&gt; &lt;add name="mysqlconnection" connectionString="Initial catalog=calculator; data source=10.2.108.251; User Id=sa; Password=abc@123"/&gt; &lt;/connectionStrings&gt; &lt;system.web&gt; &lt;compilation debug="true" /&gt; &lt;/system.web&gt; &lt;!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="Calculator1.CalculatorService1" behaviorConfiguration="Calculator1.BasicCalculator"&gt; &lt;endpoint address="" binding="wsHttpBinding" contract="Calculator1.ICalculator1"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="http://localhost:8732/Design_Time_Addresses/Calculator1/Service1/" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="Calculator1.BasicCalculator"&gt; &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt; &lt;serviceMetadata httpGetEnabled="True"/&gt; &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --&gt; &lt;serviceDebug includeExceptionDetailInFaults="False" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>app.config that i generated using SvcUtil.exe</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="BasicHttpBinding_ICalculator1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://localhost:9001/CalculatorService1" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICalculator1" contract="ICalculator1" name="BasicHttpBinding_ICalculator1" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>Windows sErvices file</p> <pre><code>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 System.ServiceModel.Description; namespace WindowsSErviceCalculator1 { public partial class CalculatorWindowsService1 : ServiceBase { ServiceHost m_svcHost = null; public CalculatorWindowsService1() { InitializeComponent(); } protected override void OnStart(string[] args) { if (m_svcHost != null) { m_svcHost.Close(); } string strAdrHTTP = "http://localhost:9001/CalculatorService1"; Uri[] adrbase = { new Uri(strAdrHTTP) }; m_svcHost = new ServiceHost(typeof(Calculator1.CalculatorService1), adrbase); ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior(); m_svcHost.Description.Behaviors.Add(mBehave); BasicHttpBinding httpb = new BasicHttpBinding(); m_svcHost.AddServiceEndpoint(typeof(Calculator1.ICalculator1), httpb, strAdrHTTP); m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); m_svcHost.Open(); } protected override void OnStop() { if (m_svcHost != null) { m_svcHost.Close(); m_svcHost = null; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload