没有可以通过操作接受消息的频道

时间:2012-01-04 10:33:07

标签: wcf web-services

当我通过 WcfTestClient访问我的web服务时,它会在几秒内返回几百个结果,所以我的web服务工作正常。

现在,当我尝试通过我的应用程序访问时,它会引发各种错误。
我的webservice在一个托管在Visual Studio上的网站上,我在localhost上访问它,当我导航到端点时,它显示没有错误(只是关于如何生成代理类的消息)。
我已经有了另一个webservice + app,这要归功于那里的亲切的绅士:WCF webservice - can't use it in production。显然我复制粘贴配置文件,但没有运气 代理类由Visual Studio自动生成,通过“添加Web服务参考”。

我确实有那里描述的症状:http://webservices20.blogspot.com/2009/04/which-binding-to-use-wshttpbinding-or.html但是这个网站没有提出具体的解决方案,所以对我没什么帮助。

IPushMail服务接口(在DLL中):

Imports System.ServiceModel
Imports System.Collections.Generic
Imports System.ServiceModel.Web

<ServiceContract()> _
Public Interface IPushMail

    <OperationContract()> _
    <WebGet(UriTemplate:="GetEmails")> _
    Function GetEmails() As List(Of CMS.Mail.MailSerialiserPushMail)

    <OperationContract()> _
    <WebGet(UriTemplate:="IncrementerNumero")> _
    Function Incrementer() As Boolean

End Interface

PushMail webservice类(在站点的App_Code文件夹中):

Imports System.Collections.Generic

Public Class PushMail
    Implements IPushMail

    Public Function GetEmails() As List(Of CMS.Mail.MailSerialiserPushMail) Implements IPushMail.GetEmails
        Dim mails As New List(Of CMS.Mail.MailSerialiserPushMail)
        ' get mails
        Return mails
    End Function

    Public Function Incrementer() As Boolean Implements IPushMail.Incrementer
        ' update record
        Return True
    End Function

End Class

PushMail应用程序:

Imports System.Collections.Generic
Imports System.Text

Module PushMail

    Sub Main()
        Dim pmClient As New PushMailService.PushMailClient()
        Dim mails As List(Of PushMailService.MailSerialiserPushMail) = pmClient.GetEmails()
        For Each m In mails
            ' do stuff
        Next
        If (pmClient.Incrementer()) Then
            Console.WriteLine("FINI")
        End If
        pmClient.Close()
    End Sub

End Module

Web.Config:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="wsHttpBinding" allowCookies="true" maxReceivedMessageSize="200000000" maxBufferPoolSize="200000000" useDefaultWebProxy="true">
                <security mode="Transport">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                </security>
            </binding>
            <binding name="NoSecurityBinding" allowCookies="true" maxReceivedMessageSize="200000000" maxBufferPoolSize="200000000" useDefaultWebProxy="true">
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <!-- here are a few other behaviors -->
            <behavior name="PushMailBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
                <serviceCredentials>
                    <windowsAuthentication allowAnonymousLogons="true" />
                </serviceCredentials>
                <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <!-- here are a few other services -->
        <service behaviorConfiguration="PushMailBehavior" name="PushMail">
            <endpoint address="" binding="wsHttpBinding" contract="IPushMail" bindingConfiguration="NoSecurityBinding">
                <identity>
                    <dns value="localhost"/>
                    <userPrincipalName value=".\NetworkService" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

App.Config:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IPushMail" closeTimeout="20:00:00"
                openTimeout="20:00:00" receiveTimeout="20:00:00" sendTimeout="20:00:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="200000000"
                    maxArrayLength="200000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="20:00:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="false" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:60308/WebServices/PushMail.svc"
            behaviorConfiguration="PushMailBehavior" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IPushMail" contract="PushMailService.IPushMail"
            name="WSHttpBinding_IPushMail">
            <identity>
                <userPrincipalName value=".\NetworkService" />
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
    <behaviors>
        <endpointBehaviors>
            <behavior name="PushMailBehavior">
                <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>

以下是我得到的错误:

应用程序抛出一条通用消息:“从另一方收到了一个不安全的错误或错误的安全故障。请参阅故障代码和详细信息的内部故障异常”。 InnerException没有多大帮助:“无法处理消息。这很可能是因为操作xxx不正确或者因为消息包含无效的过期安全上下文令牌,或者因为绑定之间存在不匹配”。

跟踪日志稍微详细一些。它首先给我两个类似的警告,都说“指定的域名不存在或无法联系”。

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131076</EventID>
<Type>3</Type>
<SubType Name="Warning">0</SubType>
<Level>4</Level>
<TimeCreated SystemTime="2012-01-04T10:05:57.8896060Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{7d9b9578-467c-4949-ad5e-380d4ae6a0b0}" />
<Execution ProcessName="WebDev.WebServer" ProcessID="17264" ThreadID="4" />
<Channel />
<Computer>PC-THOMAS-WIN7</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
<TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier>
<Description>Traitement d’une exception.</Description>
<AppDomain>cf2e76e7-10-129701451365074680</AppDomain>
<Exception>
<ExceptionType>System.ComponentModel.Win32Exception, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Le domaine spécifié n’existe pas ou n’a pas pu être contacté</Message>
<StackTrace>
à System.ServiceModel.UpnEndpointIdentity.GetUpnFromDownlevelName(String downlevelName)
à System.ServiceModel.UpnEndpointIdentity.GetUpnFromWindowsIdentity(WindowsIdentity windowsIdentity)
</StackTrace>
<ExceptionString>System.ComponentModel.Win32Exception: Le domaine spécifié n’existe pas ou n’a pas pu être contacté
   à System.ServiceModel.UpnEndpointIdentity.GetUpnFromDownlevelName(String downlevelName)
   à System.ServiceModel.UpnEndpointIdentity.GetUpnFromWindowsIdentity(WindowsIdentity windowsIdentity)</ExceptionString>
<NativeErrorCode>54B</NativeErrorCode>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

更进一步,它显示一个错误:“没有可以接受带有动作xxx的消息的频道”。

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2012-01-04T10:05:57.9286099Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{22dc2d84-586b-4221-aae4-d529e4b7560a}" />
<Execution ProcessName="WebDev.WebServer" ProcessID="17264" ThreadID="4" />
<Channel />
<Computer>PC-THOMAS-WIN7</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Génération d’une exception.</Description>
<AppDomain>cf2e76e7-10-129701451365074680</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.EndpointNotFoundException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Aucun canal ne pouvait accepter le message avec l’action « http://tempuri.org/IPushMail/GetEmails ».</Message>
<StackTrace>
à System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception e, Message message)
à System.ServiceModel.Channels.DatagramChannelDemuxer`2.ProcessItem(TInnerItem item)
à System.ServiceModel.Channels.DatagramChannelDemuxer`2.HandleReceiveResult(IAsyncResult result)
à System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnReceiveCompleteStatic(IAsyncResult result)
à System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
à System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
à System.ServiceModel.Channels.ReplyChannel.HelpReceiveRequestAsyncResult.OnReceiveRequest(IAsyncResult result)
à System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
à System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
à System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item)
à System.ServiceModel.Channels.InputQueue`1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)
à System.ServiceModel.Channels.InputQueue`1.EnqueueAndDispatch(T item, ItemDequeuedCallback dequeuedCallback, Boolean canDispatchOnThisThread)
à System.ServiceModel.Channels.InputQueueChannel`1.EnqueueAndDispatch(TDisposable item, ItemDequeuedCallback dequeuedCallback, Boolean canDispatchOnThisThread)
à System.ServiceModel.Channels.SingletonChannelAcceptor`3.Enqueue(QueueItemType item, ItemDequeuedCallback dequeuedCallback, Boolean canDispatchOnThisThread)
à System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, ItemDequeuedCallback callback)
à System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
à System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
à System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
à System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
à System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
à System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
à System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
à System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
à System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, 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)
</StackTrace>
<ExceptionString>System.ServiceModel.EndpointNotFoundException: Aucun canal ne pouvait accepter le message avec l’action « http://tempuri.org/IPushMail/GetEmails ».</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

看起来无法联系域(localhost),但我可以使用WcfTestClient访问它!我真的不明白......

感谢您的帮助......

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案...... web.config中有establishSecurityContext="true",app.config中有establishSecurityContext="false"。我在app.config中将它设置为true,现在它可以工作......