Может ли кто-нибудь сказать мне метод размещения библиотеки служб WCF в качестве службы Windows? Я попытался следовать различным ссылкам, но всегда получаю какую-то или другую ошибку. Либо служба запускается и останавливается немедленно, либо клиент не может получить доступ к службе, размещенной на окнах. Я использую простое приложение WPF в качестве клиента.Хостинг службы WCF как WindowsService?
Также может кто-нибудь сказать мне разницу между точкой адресом конца и базовым адресом и то, что должно быть там установлены в то время как хостинг WCF в качестве службы Windows
App.config для WCF службы
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="mysqlconnection" connectionString="Initial catalog=calculator; data source=10.2.108.251; User Id=sa; [email protected]"/>
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- 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. -->
<system.serviceModel>
<services>
<service name="Calculator1.CalculatorService1" behaviorConfiguration="Calculator1.BasicCalculator">
<endpoint address="" binding="wsHttpBinding" contract="Calculator1.ICalculator1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/Calculator1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Calculator1.BasicCalculator">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- 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 -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
приложения .config, что я создан с помощью svcUtil.exe
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<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">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9001/CalculatorService1"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICalculator1"
contract="ICalculator1" name="BasicHttpBinding_ICalculator1" />
</client>
</system.serviceModel>
</configuration>
Службы Windows файл
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;
}
}
}
}
Вам не нужно использовать 'svcutil.exe'. Щелкните правой кнопкой мыши раздел «Ссылки» в Visual Studio и выберите «Добавить ссылку на службу». Для этого нужно запустить службу. –
Я раньше делал это с «Добавить ссылку на службу» ранее ... но использовал, чтобы получить ту же ошибку..так, на этот раз я пошел с svcutil.exe – Siddhant