C#中的Windows服务

C#中的Windows服务

本文介绍了C#中的Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此链接创建了一项服务: []



我为https配置了我的配置,但无法启动我的服务。我收到此错误



服务无法启动.System.InvalidOperationException:Contract需要Session,但Binding'WSHttpBinding'不支持它或配置不正确支持它。



1.

I've created a service using this link :http://arcanecode.com/2007/05/22/windows-services-in-c-getting-started-part-2/[^]

I configure my config for https, but cannot start my service. I get this error

"Service cannot be started. System.InvalidOperationException: Contract requires Session, but Binding 'WSHttpBinding' doesn't support it or isn't configured properly to support it."

1.

<service name="Service.MyService" behaviorConfiguration="MyServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:443/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyServiceEndpoint" contract="IMyService"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>





2.



2.

<wsHttpBinding>
    <binding name="MyServiceEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
    </binding>
</wsHttpBinding>





3.



3.

<serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>





有人可以帮帮我吗?我还应该做些什么呢?



谢谢所有



Can anybody help me? What else I should do for starting it?

Thanks all

推荐答案

[ServiceContract(SessionMode=SessionMode.Required)]
public interface IMyService
{

}

 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
 public class MyService: IMyService
 {
 .
 .
 }



您可以根据您的选择更改实例上下文模式 []更多



这篇关于C#中的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:47