C# .NET - web service exception with desktop application

Asked By mostafa hamdy on 13-Oct-10 10:40 AM
Hello all
I have desktop application built using C# and this application uses some web service hosted in some other server and it's working correctly , and I can access its URL from my web browser, but when I set the same URL in the app .config  of  my desktop application and run it I get the following exception:

===================================================
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory factory)
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Mindworking.Installer.InstallerManager.InstallerService.ProductServiceSoap.ValidateLicense(ValidateLicenseRequest request)
   at Mindworking.Installer.InstallerManager.InstallerService.ProductServiceSoapClient.Mindworking.Installer.InstallerManager.InstallerService.ProductServiceSoap.ValidateLicense(ValidateLicenseRequest request) in F:\SVN.MindWorkin\ClientInstaller\InstallerManager\Service References\InstallerService\Reference.cs:line 1338
   at Mindworking.Installer.InstallerManager.InstallerService.ProductServiceSoapClient.ValidateLicense(String machineInfo, String licenseKey, String email) in F:\SVN.MindWorkin\ClientInstaller\InstallerManager\Service References\InstallerService\Reference.cs:line 1347
   at InstallerWizard.LicenseValidation.ValidateInputs() in F:\SVN.MindWorkin\ClientInstaller\InstallerManager\InstallerPages\LicenseValidation.cs:line 361}
=============================================
please if any body get this error so far or get what I mean and can help me please send me
regards
Mostafa

Vasanthakumar D replied to mostafa hamdy on 13-Oct-10 10:59 AM
Hi,

you have access to access the webserver.

Please provide authentication for the request...

check here for how to authenticate the webserivce...

http://msdn.microsoft.com/en-us/library/ms996415.aspx

Regards,
Vasanth