C#中的Windows服务 [英] Windows Services in C#

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

问题描述

我使用此链接创建了一项服务: http://arcanecode.com/2007/05/22/windows-services-in-c-getting-started-part-2/ [ ^ ]



我为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

推荐答案

尝试添加以下属性你的Service类实现了IMyService。



例如:

Try adding the following attributes to your Service class which implements IMyService.

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

}

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



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


谢谢Jibesh,

尝试了你的建议,但它没有用。但是我发现 BasicHttpBinding 不支持 PerSession 。一旦我将绑定更改为 WsHttpBinding ,它就能正常工作。



感谢您的输入



视为

Pat
Thanks Jibesh,
tried what you suggested but it didn't work. However I since discovered that BasicHttpBinding does not support PerSession. Once I changed the binding to WsHttpBinding it worked correctly.

thanks for your input

regards
Pat


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆