我正在尝试为现有 WCF 服务启用额外的 net.tcp 端点(使用用户名身份验证)。该服务托管在 IIS7 中。
针对服务执行客户端会返回套接字连接已中止的错误。启用针对服务的跟踪显示抛出以下异常:
System.ArgumentOutOfRangeException
该参数的值必须为正。
参数名称:maxAccepts
实际值为 0。
我很困惑,因为据我所知,端口共享应该通过配置禁用(见下文),但它仍然通过端口共享代码进行调用(再次,据我所知, )。无论如何,我找不到任何方法来指定这个 maxAccepts 值;谷歌对此一无所知,并且 maxPendingAccepts 值似乎也没有做到这一点。我该如何解决该错误?
该服务的配置文件包含 net.tcp 端点的以下内容:
<bindings>
<customBinding>
<binding name="netTcp">
<security authenticationMode="UserNameOverTransport" />
<windowsStreamSecurity />
<tcpTransport portSharingEnabled="false" listenBacklog="10" maxPendingAccepts="10" maxPendingConnections="10" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="netTcp">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Asi.Soa.ServiceModelEx.NullUserNamePasswordValidator, Asi.Soa.ServiceModelEx" />
<clientCertificate>
<authentication certificateValidationMode="None"/>
</clientCertificate>
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Asi.Soa.ServiceModelEx.ClaimsAuthorizationPolicy, Asi.Soa.ServiceModelEx" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
</behaviors>
完整的异常堆栈跟踪为:
System.ServiceModel.Channels.ConnectionAcceptor..ctor(IConnectionListener listener, Int32 maxAccepts, Int32 maxPendingConnections, ConnectionAvailableCallback callback, ErrorCallback errorCallback)
System.ServiceModel.Channels.ConnectionDemuxer..ctor(IConnectionListener listener, Int32 maxAccepts, Int32 maxPendingConnections, TimeSpan channelInitializationTimeout, TimeSpan idleTimeout, Int32 maxPooledConnections, TransportSettingsCallback transportSettingsCallback, SingletonPreambleDemuxCallback singletonPreambleCallback, ServerSessionPreambleDemuxCallback serverSessionPreambleCallback, ErrorCallback errorCallback)
System.ServiceModel.Channels.SharedTcpTransportManager.CreateConnectionDemuxer()
System.ServiceModel.Channels.SharedTcpTransportManager.OnDuplicatedVia(Uri via, Int32& connectionBufferSize)
System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.HandleOnVia(DuplicateContext duplicateContext)
System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.System.ServiceModel.Activation.IConnectionDuplicator.BeginDuplicate(DuplicateContext duplicateContext, AsyncCallback callback, Object state)
AsyncInvokeBeginBeginDuplicate(Object , Object[] , AsyncCallback , Object )
System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Dispatch(MessageRpc& rpc, Boolean isOperationContextSet)
System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)
System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
System.ServiceModel.Channels.TracingConnection.TracingConnectionState.ExecuteCallback()
System.ServiceModel.Channels.TracingConnection.WaitCallback(Object state)
System.ServiceModel.Channels.PipeConnection.OnAsyncReadComplete(Boolean haveResult, Int32 error, Int32 numBytes)
System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
编辑:我已安装非 HTTP WCF 激活组件,运行 ServiceModelReg.exe,将 net.tcp 和 net.pipe 添加到列表中IIS 管理器中启用的协议等。没有乐趣。
我还编写了一个快速的 Windows 服务来托管该服务(对我们来说不是理想的长期解决方案),并且 Net TCP 连接在那里工作正常,因此它在我的配置或代码中似乎没有任何内容,这意味着 IIS 中有问题。应用程序的应用程序池是否必须在集成模式下运行?我尝试了两种方式,似乎没有什么区别,但我们的应用程序当前安装在经典模式下。
I am trying to enable an additional net.tcp endpoint (which uses Username authentication) for an existing WCF service. The service is hosted in IIS7.
Executing a client against the service returns an error that the socket connection was aborted. Enabling tracing against the service reveals the following exception is thrown:
System.ArgumentOutOfRangeException
The value of this argument must be positive.
Parameter name: maxAccepts
Actual value was 0.
I'm confused, because as best I can tell port sharing should be disabled by the configuration (see below), but it's still calling through the port sharing code (again, as best I can tell). In any case, I can't find any way to specify this maxAccepts value; Google doesn't know anything about it, and the maxPendingAccepts value doesn't seem to do it. How do I resolve the error?
The service's config file contains the following for the net.tcp endpoint:
<bindings>
<customBinding>
<binding name="netTcp">
<security authenticationMode="UserNameOverTransport" />
<windowsStreamSecurity />
<tcpTransport portSharingEnabled="false" listenBacklog="10" maxPendingAccepts="10" maxPendingConnections="10" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="netTcp">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Asi.Soa.ServiceModelEx.NullUserNamePasswordValidator, Asi.Soa.ServiceModelEx" />
<clientCertificate>
<authentication certificateValidationMode="None"/>
</clientCertificate>
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Asi.Soa.ServiceModelEx.ClaimsAuthorizationPolicy, Asi.Soa.ServiceModelEx" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
</behaviors>
The full exception stack trace is:
System.ServiceModel.Channels.ConnectionAcceptor..ctor(IConnectionListener listener, Int32 maxAccepts, Int32 maxPendingConnections, ConnectionAvailableCallback callback, ErrorCallback errorCallback)
System.ServiceModel.Channels.ConnectionDemuxer..ctor(IConnectionListener listener, Int32 maxAccepts, Int32 maxPendingConnections, TimeSpan channelInitializationTimeout, TimeSpan idleTimeout, Int32 maxPooledConnections, TransportSettingsCallback transportSettingsCallback, SingletonPreambleDemuxCallback singletonPreambleCallback, ServerSessionPreambleDemuxCallback serverSessionPreambleCallback, ErrorCallback errorCallback)
System.ServiceModel.Channels.SharedTcpTransportManager.CreateConnectionDemuxer()
System.ServiceModel.Channels.SharedTcpTransportManager.OnDuplicatedVia(Uri via, Int32& connectionBufferSize)
System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.HandleOnVia(DuplicateContext duplicateContext)
System.ServiceModel.Channels.SharedConnectionListener.SharedListenerProxy.System.ServiceModel.Activation.IConnectionDuplicator.BeginDuplicate(DuplicateContext duplicateContext, AsyncCallback callback, Object state)
AsyncInvokeBeginBeginDuplicate(Object , Object[] , AsyncCallback , Object )
System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Dispatch(MessageRpc& rpc, Boolean isOperationContextSet)
System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)
System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
System.ServiceModel.Channels.TracingConnection.TracingConnectionState.ExecuteCallback()
System.ServiceModel.Channels.TracingConnection.WaitCallback(Object state)
System.ServiceModel.Channels.PipeConnection.OnAsyncReadComplete(Boolean haveResult, Int32 error, Int32 numBytes)
System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Edit: I have installed the non-HTTP WCF activation components, run ServiceModelReg.exe, added net.tcp and net.pipe to the list of enabled protocols in IIS Manager, etc. No joy.
I've also written a quick Windows Service to host the service (not the ideal long-term solution for us), and the Net TCP connection works fine there, so it doesn't appear to be anything in my configuration or code, which means something isn't right in/with IIS. Does the app pool for the application have to be running in Integrated mode? I tried it both ways, it didn't seem to make a difference, but our app currently is installed in Classic mode.
发布评论
评论(2)
据我所知,问题很简单,当一个是 Soap11 端点,一个是 NetTcp 端点时,.NET 不喜欢在同一个 IIS 应用程序中托管两个服务。删除 Soap11 端点可使 NetTcp 端点正常工作而不会出现错误。
我们已转向使用 Windows 服务托管 NetTcp 端点并将 Soap11 端点保留在 IIS 中的模型。
如果有人知道如何在 IIS 的同一应用程序中托管 NetTcp 和 Soap11 服务,我很想听听。
As best I can determine, the problem is simply that .NET does not like hosting two services in the same IIS application when one is a Soap11 endpoint and one is a NetTcp endpoint. Removing the Soap11 endpoint allows the NetTcp endpoint to work without error.
We've moved to a model where we are using a Windows Service to host the NetTcp endpoint and left the Soap11 endpoint in IIS.
If anyone figures out how to host both a NetTcp and Soap11 service in the same application in IIS, I'd love to hear about it.
Net.tcp 不能在 IIS7 上开箱即用,有很多东西需要激活。
请参阅:http://labs.episerver.com/en/Blogs/Paul-Smith/Dates/2008/6/Hosting-non-HTTP-based-WCF-applications-in-IIS7/
Net.tcp does not work on IIS7 out-of-the-box, there are a number of things that need to be activated.
See: http://labs.episerver.com/en/Blogs/Paul-Smith/Dates/2008/6/Hosting-non-HTTP-based-WCF-applications-in-IIS7/