Reputation: 6037
When I access my webservice via WcfTestClient, it returns me a few hundred results in a few seconds, so my webservice works fine.
Now, when I try to access it via my application, it throws me all kinds of errors.
My webservice is on a website hosted with Visual Studio, I access it on localhost, and when I navigate to the endpoint it shows me no error (just the message on how to generate a proxy class).
I already have another webservice+app, which work fine thanks to the kind gentlemen there : WCF webservice - can't use it in production . Obviously I copy-pasted the config files, but no luck.
The proxy class is auto-generated by Visual Studio, via "Add Webservice Reference".
I have exactly the symptoms described there : http://webservices20.blogspot.com/2009/04/which-binding-to-use-wshttpbinding-or.html but this site does not suggest concrete solutions, so it's not of much help to me.
The IPushMail service interface (in a 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
The PushMail webservice class (in the App_Code folder of the site) :
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
The PushMail app :
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>
And here are the errors I get :
The app throws a generic message : "An unsecured error or incorrectly secured fault was received from the other party. See the inner fault exception for the fault code and detail". The InnerException is not of much more help : "The message could not be processed. This is most likely because the action xxx is incorrect or because the message contains an invalid expired security context token or because there is a mismatch between bindings".
The trace log is a bit more detailed. It starts by giving me two similar warnings, both saying "The specified domain either does not exist or could not be contacted".
<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>
A bit further down the line, it shows an error : "There was no channel that could accept the message with action 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>
It looks like the domain (localhost) cannot be contacted, but I can access it with WcfTestClient ! I really don't get it...
Thanks for your help...
Upvotes: 1
Views: 6060
Reputation: 6037
OK, I have found the solution... There was establishSecurityContext="true"
in the web.config, and establishSecurityContext="false"
in the app.config. I set it to true in the app.config, and now it works...
Upvotes: 2