The WCF program always pops up a bug when it's recently working on a WCF program "The Display modal dialog box or the form is invalid when the application is not running in userinteractive mode." Specify the servicenotification or Defaultdesktoponly style to display the alert for the notification from the service application, and later capture the error with a try Catch statement and find some hints.
The Exceptiondetail, which is likely to be created by Includeexceptiondetailinfaults=true, has the following values:
System.InvalidOperationException: The Display modal dialog box or the form is invalid when the application is not running in userinteractive mode. Specify the servicenotification or Defaultdesktoponly style to display the notifications that are sent by the service application.
In System.Windows.Forms.MessageBox.ShowCore (IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton DefaultButton, messageboxoptions options, Boolean showHelp)
In System.Windows.Forms.MessageBox.Show (String text)
In DataProvider.Utils.SQLServerHelper.Open () location c:\Users\2457\Desktop\ Ningbo Highway Bureau \dataprovider (2015-10-26-final version) \utils\ DataBaseSQLServerHelper.cs: Line No. 33
In DataProvider.Utils.SQLServerHelper. ctor (String connectstr) Location c:\Users\2457\Desktop\ Ningbo Highway Bureau \dataprovider (2015-10-26-final version) \utils\ DataBaseSQLServerHelper.cs: Line No. 21
In Dataprovider.announcement. ctor () Location c:\Users\2457\Desktop\ Ningbo Highway Bureau \dataprovider (2015-10-26-final version) \announcement.cs: Line No. 21
In Createdataprovider.announcement ()
In System.ServiceModel.Dispatcher.InstanceProvider.GetInstance (InstanceContext InstanceContext, message message)
In System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance (InstanceContext InstanceContext, Message request)
In System.ServiceModel.InstanceContext.GetServiceInstance (Message message)
In System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1 (messagerpc& RPC)
In System.ServiceModel.Dispatcher.MessageRpc.Process (Boolean Isoperationcontextset)}
After seeing the call information for these stacks, System.Windows.Forms.MessageBox.ShowCore is at the heart of the problem, which is that the code for the form cannot appear in the WCF program, such as the MessageBox, OpenFileDialog and other related code, if this information appears, the program will often appear this error, should be for our WCF program is deployed on IIS above, IIS is not allowed to handle this. Then take a look at our code.
private void Open ()
{
Try
{
Sqlconn.open ();//Open database
}
catch (Exception ex)
{
MessageBox.Show (ex. Message);
}
}
Then remove the MessageBox that appears throughout the program. At least two conclusions can be drawn from this bug:
1 You must learn to use try catch to catch unknown errors, then find the relevant stack information and then step through the prompts to fix the problem.
2 in a WCF program, you must not use any class or code related to the form.
Display modal dialog boxes or forms when the application is not running in userinteractive mode