Showing posts with label Troubleshooting. Show all posts
Showing posts with label Troubleshooting. Show all posts

Friday, April 18, 2008

Error: System.ServiceModel.Channels

Recently I came across interesting error messages while calling a WCF Service Hosted in IIS 6.0 on Windows 2003 Server. From the error message, I could not figure out the real cause. But after doing some research and changing few configuration information and changing the code, it appears that these solutions fixed these errors.

 Errors

System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)     at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)     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) 
 Or
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)
Solutions
1.       Increase the default value of maxConcurrentCalls from 16 to 50 and maxConcurrentSessions from 10 to 50. You can increase even higher based on your need.
<serviceBehaviors>
    <behavior name=" ServiceBehavior1">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50"/>     
     <serviceTimeouts />
    </behavior>  
   </serviceBehaviors>
 
2.       Use “Using Block” in Service Client to gracefully dispose the object. Also, explicitly close ChannelFactory and Client.
          Using svcClient As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
           ' Or  Using svcClient As ServiceReference1.Service1Client = New ServiceReference1.Service1Client("EndPointConfigName", "ServiceRemoteAddress")
            'Do the Service related stuff here
            'Before you end the process explicitly Close Client's ChannelFactory and Client
            'Note: Closing the ChannelFactory Closes Client as well but Closing Client does not close the ChannelFactory
            svcClient.ChannelFactory.Close()
            svcClient.Close()
        End Using

Thursday, April 17, 2008

Error: Could not establish trust relationship for the SSL/TLS secure channel with authority

I got this error when calling a WCF Service over HTTPS. A Similar error can also occurs when you try calling a web service programmatically over SSL (HTTPS) and certificate is either not valid or Certificate is attached to a domain and you are not using the domain name but the machine name or IP address. So, what to do in that case if you don’t care about certificate and would like to accept all certificates. I found that it can be done using one of two ways. 

Main Class – Where you are calling the Web Service, add following Import Statements
Imports System.Security.Cryptography.X509Certificates
Imports System.Net.Security
Imports System.Net
 
Public Class MyWebServiceCall
 
    Public Sub CallServiceUsingFunction()
        'Instanciate the Service here
        'Set all paramaters which you need to pass
        'Before You call the Service
        ServicePointManager.ServerCertificateValidationCallback = AddressOf TrustAllCertificatesCallback
        'Call your service Now.......
    End Sub
 
 
    Public Shared Function TrustAllCertificatesCallback(ByVal sender As Object, ByVal cert As X509Certificate, _
                                                 ByVal chain As X509Chain, ByVal errors As SslPolicyErrors) As Boolean
        Return True
    End Function
    Public Sub CallServiceUsingClass()
        'Instanciate the Service here
        'Set all paramaters which you need to pass
        'Before You call the Service
        Dim CertOverride As New CertificateOverride
        ServicePointManager.ServerCertificateValidationCallback = AddressOf CertOverride.RemoteCertificateValidationCallback
        'Call your service Now.......
    End Sub
End Class
 CertificateOverride Class - An Alternate Option
Public Class CertificateOverride
    Public Function RemoteCertificateValidationCallback(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, _
            ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
        Return True
    End Function
End Class

 

Saturday, May 26, 2007

Server Error: HTTP Error 500.19 - Internal Server Error

You might have come across this error while working on a WCF project on Vista, IIS 7.0 with Visual Studio 2005. Actually Microsoft has tightened the security on VISTA and most of the time it is annoying when it asks your permission. Following is the detail error message I received while trying to run a WCF project, however I found a simple solution to fix it.

Server Error

HTTP Error 500.19 - Internal Server Error
Description: The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code: 0x80070005
Notification: BeginRequest
Module: IIS Web Core
Requested URL: http://localhost:80/ProductsService/ProductsService.svc
Physical Path: C:\Test\ProductsService\ProductsService\ProductsService.svc
Logon User: Not yet determined
Logon Method: Not yet determined
Handler: Not yet determined
Config Error: Cannot read configuration file
Config File: \\?\C:\Test\ProductsService\ProductsService\web.config
Config Source:
   -1:
    0:
More Information...This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.

Server Version Information: Internet Information Services 7.0.

Solution: Compile the project and place the deployable files under C:\Inetpub\wwwroot\<projectname>. Make sure that the physical path of the respective Application (e.g. ProductsService in above error case) under IIS now points to new path. 


It looks like that if you run your application under IIS 7 and the physical path of any application is other than wwwroot then it will give the above error message or you provide that folder some special permission so that IIS can access it.

Monday, May 07, 2007

AJAX Error: 'Sys' is undefined

If you are using AJAX enabled web site or project, you may come across this error message. I got this error message too and spent few hours to fix this problem. I tried finding all possible solutions on Google and finally concluded with following three steps.
 

    • Web.Config: Make sure your web.config is correctly configured to handle AJAX enabled request. You might have created a project which was not AJAX enabled earlier and now you want to Ajaxfy. The best solution is creating a new project ASP.NET AJAX Enabled Web Site. It will create a Web.config file by default. Compare this Web.config file with your other project’s Web.config file which is casuing the error. Make sure that you are not missing any new section. You can simply copy and paste it at appropriate place. For detail information you can also visit at  http://ajax.asp.net/docs/configuringASPNETAJAX.Aspx
    •  Using Master Page: If your ASP.NET web page is using a Master Page, make sure your Script Manager Control is placed in Master Page only. Content page should not be using Script Manager Control.
    • Regular Web Page: If you are not using a Master Page then each ASP.NET web page must have its own Script Manager Control.

Tuesday, January 16, 2007

Error : Internet Explorer cannot download ...

If you see Error message : Internet Explorer cannot download "filename" from "Servername"

Internet Explorer was not able to open this Internet site.

The requested site is either unavailable or cannot be found. Please try again

Then, this error usually occurs sometime while downloading a document which can be in form of PDF file, Doc file, XLS or text file. There are at least 4 possible reasons which can cause this error. I have also found their solutions. My assumption is - you are running your web site on IIS.

 

Reason 1:  You have checked Enable content expiration

Solution: 

a) Select the appropriate virtual directory on IIS, right click and select Properties then click on HTTP Headers tab.

b) Make sure that the checkbox for Enable content expiration is Unchecked.

  

Reason 2: If path for virtual directory is a shared folder and located on another computer

Solution:

a) Make sure that the Network directory is a UNC path (not mapped disks drive, because sometime you may loose mapping and it will generate an error).

b) You must provide a user name along with domain name when you click on Contact As button to provide Network Directory Security Credentials.

 

Reason 3: You are sure that you do not have issues due to above reasons but you are not able to download specific file type (e.g. .pdf, .doc etc)

Solution:

a) Select the appropriate virtual directory on IIS, right click and select Properties then click on HTTP Headers tab.

b) Click on button MIME Types and add appropriate MIME Types, if you would like to add for all types of file then click on button New, enter .* for Extension and application/text for MIME Type and then click on OK.

   

Reason 4: You checked all the above reasons and applied the solutions but you are not able to download or open a file.

Solution: Please follow the following steps

a) Internet Explorer-> Tools menu-> Internet Options-> Advanced tab

b) Go to the Security section all the way at the bottom.

c) Clear the check on the "Do not save encrypted pages to disk"

d) Close all Internet Explorer windows

e) Start IE and download the file again

  

 


Sunday, December 31, 2006

Error "System.Web.HttpException: Maximum request length exceeded"

I have come across this error multiple times at work. This problem occurs because the default value for the maxRequestLength parameter in the section of the Machine.config or Web.Config file is 4096 (4 megabytes). As a result, files that are larger than this value are not uploaded by default.

To resolve this problem, use one of the following methods:

  • In the Machine.config file, change the maxRequestLength attribute of the <httpRuntime> configuration section to a larger value. This change affects the whole computer.
  • In the Web.config file, override the value of maxRequestLength for the application. For example, the following entry in Web.config allows files that are less than or equal to 1 GB to be uploaded:
                         <httpRuntime maxRequestLength="1048576" />

Max value for maxRequestLength attribute is "1048576" (1 GB) for .NET Framework 1.0 or 1.1 and "2097151" (2 GB) for .NET Framework 2.0.

Note: During the upload process of large files, built-in ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of the memoryLimit attribute of the processModel tag in the Machine.config file. More info you can find in Microsoft KB article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626