Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

c# - WCF SOAP Service method timeout for no reason

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.

here is the 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>

The service cotnract:

[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();
    }

And implementation:

[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()
        {
        }
    }

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...