繁体   English   中英

WCF SOAP 服务方法无故超时

[英]WCF SOAP Service method timeout for no reason

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

这是配置:

<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。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM