我有一个简单的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/>
和<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.
如果两者都保留在绑定中,则服务在本地工作,但远程客户端在调用方法时永远不会返回响应。