C# WCF - 无法调用服务

Kei*_*ows 3 c# wcf

尝试使用 WCF 测试客户端访问我的新 Web 服务时出现以下错误。奇怪的是每隔一段时间它就会执行一次然后开始弹出这个错误。

调用服务失败。可能原因:服务离线或无法访问;客户端配置与代理不匹配;现有代理无效。有关更多详细信息,请参阅堆栈跟踪。您可以尝试通过启动新代理、恢复到默认配置或刷新服务来恢复。

我的代码(界面):

[ServiceContract(Namespace = "http://rivworks.com/Services/2010/04/19")]
public interface ISync
{
    [OperationContract]
    bool Execute(long ClientID);
}
Run Code Online (Sandbox Code Playgroud)

我的代码(类):

public class Sync : ISync
{
    #region ISync Members
    bool ISync.Execute(long ClientID)
    {
        return model.Product(ClientID);
    }
    #endregion
}
Run Code Online (Sandbox Code Playgroud)

我的配置(编辑 - 发布了整个 serviceModel 部分):

<system.serviceModel>
  <diagnostics performanceCounters="Default">
    <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="true" />
  </diagnostics>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
  <behaviors>
    <endpointBehaviors>
      <behavior name="JsonpServiceBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="SimpleServiceBehavior">
        <serviceMetadata httpGetEnabled="True" policyVersion="Policy15"/>
      </behavior>
      <behavior name="RivWorks.Web.Service.ServiceBehavior">
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <services>
    <service name="RivWorks.Web.Service.NegotiateService" behaviorConfiguration="SimpleServiceBehavior">
      <endpoint address=""
                binding="customBinding"
                bindingConfiguration="jsonpBinding"
                behaviorConfiguration="JsonpServiceBehavior"
                contract="RivWorks.Web.Service.NegotiateService" />
      <!--<host>
        <baseAddresses>
          <add baseAddress="http://kab.rivworks.com/services"/>
        </baseAddresses>
      </host>
      <endpoint address=""
                binding="wsHttpBinding"
                contract="RivWorks.Web.Service.NegotiateService" />-->
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="RivWorks.Web.Service.NegotiateService" />
    </service>
    <service name="RivWorks.Web.Service.Sync" behaviorConfiguration="RivWorks.Web.Service.ServiceBehavior">
      <endpoint address="" binding="wsHttpBinding" contract="RivWorks.Web.Service.ISync" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>

  <extensions>
    <bindingElementExtensions>
      <add name="jsonpMessageEncoding" type="RivWorks.Web.Service.JSONPBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bindingElementExtensions>
  </extensions>

  <bindings>
    <customBinding>
      <binding name="jsonpBinding" >
        <jsonpMessageEncoding />
        <httpTransport manualAddressing="true"/>
      </binding>
    </customBinding>
  </bindings>    
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

2个问题:

  1. 我错过了什么导致此错误?
  2. 如何增加服务的超时时间?

蒂亚!

Kei*_*ows 5

发现问题...

  1. Web 服务中出现未处理的错误。
  2. The test app does not do an ABORT when it sees an error. Instead, it is left unhandled (and unreported) AND the channel is now locked because of the error.

Putting a try/catch around the inside method makes it so I can log the error and the test app does not lock up.