Hi,
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)
at ...
Does anyone have a suggestion? I'm really stuck with this.
Kind regards,
Martijn
Has anyone used the .NET Connector 3.0 within a custom SharePoint web part already?
I still haven't been able to fix the problem yet.
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:
http://sapboard.ru/forum/viewtopic.php?p=429666
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.ThrowIfEventBindingDisallowed()
at System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification)
at SAP.Middleware.Connector.RfcWebSessionProvider..ctor()
at SAP.Middleware.Connector.RfcSessionManager..cctor()
--- 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
I'm experiencing the exact same problem...
Running the code from a console application doesn't produce the exception, but that doesn't help us when we want to run it through a web service.
Best Regards,
Stefan Hansen
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
Nice to know it can be solved. ![]()
Did you create a .NET 4.0 Web Site, WCF Service or ASP.NET Web Application?
I tried creating an ASP.NET Web Application with an asmx file... and that failed.
Regards,
Stefan Hansen.
Finally solved it.
I created an empty ASP.NET Web Application targeting .NET 4.0 and added a Web Service as an .asmx file.
Regards,
Stefan
Hi Stefan,
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.
Hi Martijn,
Have you managed to find the solution for this using the .Net fw 3.5 in a sharepoint custom webpart.
I am also facing the same problem. could you please let me know if you have found out the solution.
Thanks,
Ram
Hi Ram,
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.
Kind regards,
Martijn van den Meijdenberg
Thank you for your prompt reply. Ok, atleast you gave me a confirmation that this was not a bug in .net connector
Thanks
Ram
I was facing the same issue with the latest version, you can use one version earlier (3.0.3 start to create issues).
Regards,
Christian
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
rfcFunction.Invoke(destination);
There are some Errrors....
[InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.]
System.Web.HttpApplication.ThrowIfEventBindingDisallowed() +11182675
System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification) +30
System.Web.HttpApplication.add_EndRequest(EventHandler value) +62
SAP.Middleware.Connector.RfcWebSessionProvider..ctor() +260
SAP.Middleware.Connector.RfcSessionManager..cctor() +266
[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.Control.LoadRecursive() +66
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
I had the same problem and resolved it by doing the following:
In IIS7, go to your application pool
Go to advanced settings
Change "Managed Pipeline Mode" from "Integrated" to "Classic"
That fixed it for me... Good luck all
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:
SAP.Middleware.Connector.RfcSessionManager.IsSessionProviderRegistered();
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.
Thanks for that Paul - very valuable info! Much appreciated
While testing .net WCF based restful service I encountered the same error. Resolved the issue by using the latest version of NCO 3.0 (3.0.5).
Thanks for the valuable insight but your suggestion didn't work from start. It generate type initializer exception. Is there more to what you need to do other than App_Start?
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.
Pls help.
I was getting the problem for the initializer for SAP.Middleware.Connector.RfcSessionManager
If you are getting it for SAP.Middleware.Connector.RfcDestinationManagers, try creating an instance of that class or calling a static method on that class from you App_Start event.