WCF SOAP服务方法无故超时 [英] WCF SOAP Service method timeout for no reason

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

问题描述

我有一个带有 wsHttpBinding 的 WCF SOAP 服务,我有 2 个方法,第一个执行正常,但由于某种原因,对第二个方法的调用超时.我调试了该方法,我的代码一切正常,它执行并返回,但是在客户端中,在同一台机器上,请求超时.我新建了一个WCF Service Application项目,把整个code+config复制到新项目中,运行一下,方法几次都没有超时,然后突然又开始了.

I have a WCF SOAP Service with wsHttpBinding, i have 2 methods, the first one executes fine, but for some reason the call to the second method times out. I debuged the method and the everything is fine i my code, it executes and returns, but the in the client, on the same machine, the requests times out. I created a new WCF Service Application project, copied the entire code + config to the new project, ran it, and the method didn't time out for a few times, then suddenly it started doing it again.

这里是配置:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="PolicyServiceBehavior" name="IST.Broker.Services.PolicyServiceV2.PolicyService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="PolicyServiceBindingConfiguration"
          contract="IST.Broker.Services.PolicyServiceV2.IPolicyService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:63915/" />
          </baseAddresses>
          <timeouts closeTimeout="00:01:00" openTimeout="00:01:00" />
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PolicyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647" maxConcurrentInstances="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="PolicyServiceBindingConfiguration"
                 bypassProxyOnLocal="false"
                 transactionFlow="false"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="2000000"
                 maxReceivedMessageSize="2000000"
                 messageEncoding="Text"
                 textEncoding="utf-8"
                 useDefaultWebProxy="true"
                 allowCookies="true">
          <readerQuotas
                maxDepth="2000000"
                maxStringContentLength="2000000"
                maxArrayLength="2000000"
                maxBytesPerRead="2000000"
                maxNameTableCharCount="2000000" />
          <reliableSession
                enabled="true"
                inactivityTimeout="00:01:00" />
          <security mode="None"/>
        </binding>
      </wsHttpBinding>
    </bindings>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

服务合同:

[ServiceContract(SessionMode = SessionMode.Required)]
    public interface IPolicyService
    {
        [OperationContract(IsInitiating = true)]
        void Initialize(int employeeId);

        [OperationContract(IsInitiating = false, IsTerminating = false)]
        GetPolicyResponse GetPolicy(GetPolicyRequest request);

        [OperationContract(IsInitiating = false, IsTerminating = false)]
        CreateMtplApplicationResponse CreateMtplApplication(CreateMtplApplicationRequest request);

        [OperationContract(IsInitiating = false, IsTerminating = true)]
        void SignOut();
    }

和实现:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
    public class PolicyService : IPolicyService
    {
        private Employee _currentEmployee;

        public GetPolicyResponse GetPolicy(GetPolicyRequest request)
        {
            return new GetPolicyResponse(PolicyManager.GetPolicy(request.Id, request.PolicyNumber));
        }

        public void Initialize(int employeeId)
        {
            if (!InsuranceCompaniesServiceManager.IsInitialized)
            {
                var appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
                _currentEmployee = EmployeeManager.GetEmployee(employeeId);
                InsuranceCompaniesServiceManager.Initialize(_currentEmployee, appPhysicalPath);
            }
        }

        public CreateMtplApplicationResponse CreateMtplApplication(CreateMtplApplicationRequest request)
        {
            return new CreateMtplApplicationResponse(PolicyManager.CreateMtplApplication(request.CompanyId, request.Policy.ToBusinessObject(), request.Vehicle.ToBusinessObject(),
                request.Clients.Select(x => x.ToBusinessObject()).ToList(), request.GreenCard.ToBusinessObject(), request.Sticker.ToBusinessObject()));
        }

        public void SignOut()
        {
        }
    }

该方法正在调用内部正在调用另一个服务的 DLL.

The method is calling a DLL that inside is calling another service.

推荐答案

在下面注释掉,因为它会在配置代理时自动添加.

Comment out below line because it'll be added automatically while configuring the proxy.

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

如果要查看,请右键单击您添加服务代理的服务代理,然后选择配置服务引用",您会注意到最后在服务的 URL 中添加了/mex

If you want to check, Right click on service proxy where you added service proxy, and select "Configure Service Reference" and you'll notice /mex is added in URL of the service at last

这篇关于WCF SOAP服务方法无故超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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