1

我有一个简单的 WCF 服务。它托管在 IIS 中。远程客户端能够获取元数据,并生成代理代码。但是当进行服务调用时,服务没有响应。我的 WCF 服务代码永远不会被命中。问题甚至在那之前就发生了。这是堆栈跟踪。我怎样才能解决这个问题?该服务在本地工作(即,在托管该服务的同一台机器上)。我没有进行任何身份验证等。

The open operation did not complete within the allotted timeout of 00:01:00. The
 time allotted to this operation may have been a portion of a longer timeout.

Server stack trace:
   at System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException()
   at System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.OnOpen(Tim
eSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceMod
el.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeo
ut)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeS
pan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

添加配置文件以响应评论:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>        
        <add relativeAddress="Service1.svc" service="WcfService1.Service1"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <services>      
      <service name="WcfService1.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://mymachine.mydomain.com/Service1/" />            
          </baseAddresses>                    
        </host>
        <endpoint address="Service1"
                  binding ="customBinding"
                  bindingConfiguration="NetHttpBinding"
                  contract="WcfService1.IService1"/>
      </service>
    </services>
    <bindings>
      <!-- http://msdn.microsoft.com/en-us/library/vstudio/hh323713(v=vs.100).aspx
           You must add the binding elements in the following order: Transaction Flow, Reliable Session, Security,
           Composite Duplex, One-way, Stream Security, Message Encoding, and Transport.-->
      <customBinding>
        <binding name="NetHttpBinding">
          <reliableSession />          
          <compositeDuplex />
          <oneWay />
          <binaryMessageEncoding />          
          <httpTransport maxBufferSize="2147483647"  maxReceivedMessageSize="2147483647"  />
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

客户端可以访问静态html文件,元数据页面wsdl也可以创建代理。

编辑:如果我将绑定更改为 basicHttpBinding,它可以工作。但我需要让它与这个自定义绑定一起工作。

编辑:罪魁祸首似乎是<compositeDuplex/>and<oneWay/>元素。如果我将它们从绑定中删除,它就可以工作(现在就是;为什么它不适用于元素 - 我不知道)。为了完整起见,如果我只删除一个<oneWay/><compositeDuplex/>但不是两个)我在尝试访问元数据时会收到此错误:

Binding 'CustomBinding' doesn't support creating any channel types. This often indicates that the BindingElements in a CustomBinding have been stacked incorrectly or in the wrong order. A Transport is required at the bottom of the stack. The recommended order for BindingElements is: TransactionFlow, ReliableSession, Security, CompositeDuplex, OneWay, StreamSecurity, MessageEncoding, Transport. 

如果两者都留在绑定中,则服务在本地工作,但远程客户端在调用方法时永远不会得到响应。

4

0 回答 0