I'm trying to develop a custom web part for SharePoint 2007. The web part is containing a user control that has a button.
When clicking the button some data needs to be read from SAP using the .NET connector 3.0.
Everything works fine when I use the user control in an ordinary web application. But when trying to use it in a custom web part the following exception is thrown bij the Invoke function of the .NET Connector:
The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception.
This exception has an inner exception with the following text:
Event handlers can only be bound to HttpApplication events during IHttpModule initialization.
The stack trace looks like:
at SAP.Middleware.Connector.RfcSessionManager.GetConnection(RfcDestination dest)
at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination)
Does anyone have a suggestion? I'm really stuck with this.
In the meanwhile I discovered that the .NET Connector 3.0 does not work within a Web Service as well.
Here's a thread from another forum where somebody has the same problem:
No solution there as well.
This is the stacktrace after the exception that occurs when i try to invoke a web service operation that internally works with .NET Connector:
System.TypeInitializationException: The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception. ---> System.InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.
at System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification)
--- End of inner exception stack trace ---
at SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(Object state)
at System.Threading._TimerCallback.TimerCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination)
at MyClass.MyMethod(string text)
By the way, it works when running from the debugger. But same exception occurs as in the web part when I host the web service on a web server.
Could somebody perhaps shine some light on this?
The .NET Connector 3.0 seems to work with some kind of mechanism that doesn't fit within a Web Service and Web Part (and perhaps other techniques as well...)
Or could this be a bug?
Edited by: Martijn van den Meijdenberg on Sep 8, 2011 9:55 AM
Thanks for your answer.
I'm now looking in the direction of IIS 7 configuration and/or the configuration of my web service web.config.
Try googling for "IIS7 Event handlers can only be bound to HttpApplication events during IHttpModule initialization"
I read a suggestion to run the application in classic mode instead of integrated mode. Tried that but it resulted in the application failing to start. I'm looking further into that at the moment
I managed to fix the problem with the web service.
Solution for me was to create a new empty web site with target framework 4.0. (My old one was 3.5)
This results in an almost empty web.config in opposite to a 3.5 web site.
Unfortunately for the web part this will not be a solution because a custom share point web part must target the 3.5 version of .NET. But I'm sure the solution there must have something to do with configurations of IIS and my own web.config
Sorry for the late reply. Good to hear you solved it as well.
That's the way I solved it too, but i created an empty website targeting 4.0.
So appearently that does not make any difference fortunately
I still have to figure out how to make the connector work within a sharepoint web part.
Problem there is that it needs to be .net 3.5. I'm going further with that today.
I can't exactly tell the solution, but as soon as we deployed the web part to our client's SharePoint environment the problem was gone. That made me conclude that it is not a bug in the .NET connector, but you have to find the solution somewhere in IIS configuration web.config configuration.
I'm not experienced in that.
Martijn van den Meijdenberg
I faced with Same issue. Please help me.
I'm developing program Calling SAP RFC function by SAP .NET Connector 3.0 (Nco3.0)
I complete the programe in my computer ( window XP(x86), .NET Framework3.5, .NET Connector 3.0(x86) , visual studio 2005)
rfcfunction I wanted is called very well. This is not web service.
But, After apply the source to another Server , The programe is not running. (Windows server 2008(x64), .NET Framework3.5, .NET Connector(x64))
This is webservice.
I changed App.config file to web.config file. and I made Required Libraris locate under the [bin] directory.
what it means that " The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception"
I don't know about that.....
Exception is generated at this point . it means Make the remote call
There are some Errrors....
[InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.]
System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification) +30
System.Web.HttpApplication.add_EndRequest(EventHandler value) +62
[TypeInitializationException: 'The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception]
SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(Object state) +0
System.Threading.ExecutionContext.runTryCode(Object userData) +376
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +98
SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination) +1808
MultiLoginTest.ExampleSimpleCall(String ERPID, String targetURL) in d:\NETS\SSO\SAPLogonAgent\MultiLoginTest.aspx.cs:243
MultiLoginTest.Page_Load(Object sender, EventArgs e) in d:\NETS\SSO\SAPLogonAgent\MultiLoginTest.aspx.cs:130
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Edited by: NaRaeeee on Oct 28, 2011 7:34 AM
Edited by: NaRaeeee on Oct 28, 2011 7:37 AM
To make the connector work with an application pool in integrated mode, you have to run something that will implicitly invoke the static constructor for the RfcSessionManager class from an application pool initialisation event. That way, it doesn't do it again when you call Invoke at a point where you are not supposed to register such events. Classic mode lets you get away with trying to attach this event in the wrong place, which is why no errors are thrown in that scenario.
If you have access to the Global.asax file, simply add the following line to your Application_Start event:
If you are using something like SharePoint where you can't add a Global.asax, create an HttpModule, put the above code in the Init event and register the HttpModule in your web.config.
We had many similar issues directly using NCo 3.0 from the SharePoint 2010 deployed web part, so we now always put our NCo SAP access in a WCF service (deployed to IIS App Fabirc .Net 4.0) and have the web part call the WCF service. This avoids all the SharePoint related issues.
Did anyone found solution to the following error "The type initializer for 'SAP.Middleware.Connector.RfcDestinationManagers' threw an exception."
I am getting this error when i am developing Web application or website and calling the rfc. I tried every option given here but no outcomes.