I have a Silverlight 4 application which talks to a 'manager' class, which talks to a WCF Service ( .net 4) , which uses the Microsoft.ApplicationBlocks.Data library to talk to my SQL database.
My issue is with exceptions not bubbling up to the Silverlight App.
What happens is, an insert to the database fails, creating an SQLException, this then throws the error further, to the generated service reference code used by the Manager, which, in the completed event handler, finds that the Error property is not null. This throws an event to the Silverlight app which displays a message to the user saying that an error has occured.
This works when I am locally debugging my application but fails silently when the appliaction is on the live/production server, no error message gets displayed.
If I generate the service reference from the wcf service running on the server (not locally), and use a local instance of my Silverlight App, it also works correctly which makes me think that the error is happening in the service reference (generated code) and Silverlight communication.
The service is hosted in a 'hand-coded' host application and the Silverlight app on the server is hosted in IIS. They both use http and not https.
I have scoured the Internet but found nothing that relates to this situation. I do not kill off objects, therefore preventing exceptions being returned to non-existant objects.
In short, the Manager correctly recieves and throws an event on my local system but not when deployed on the server.
WCF Experts needed please!
So, after some more fruitless searching, my collegue built a test app where he built a custom silverlight Fault Contract class based on this example:
http://msmvps.com/blogs/theproblemsolver/archive/2009/01/27/returning-exception-information-to-a-silverlight-client-through-wcf.aspx
Although this helped alot with getting the specific error from the service instead of the generic garbage Silverlight spews, we could still not get the error to display on the screen.
My previous guess that the communication was failing was incorrect. Instead, it was simply the fact that the result did not have any effect on the UI Thread. We used the Dispatcher to jump back onto the UI Thread:
Deployment.Current.Dispatcher.BeginInvoke(
() =>
{
//throw event to window which shows error window
}
);
which displayed the true error. I still do not know exactly why this was required for the app on the Production server but it worked fine on my localhost, in debug mode or not.
If anyone with more knowledge about the technicalities of this occurance reads this, please be so kind as to explain what really happened here.
Related
I've created an SNMP listener application for one of our servers that runs as a service and passively listens for any SNMP message alerts sent from another server, and when one is received is sends out a page/email to appropriate staff. I followeda few online tutorials for setting up the application as a windows service since it needs to run constantly and won't require input/interaction from a user, or interaction with any GUI/desktop applications.
For some reason, when I install the application as a service, it installs correctly, but doesn't actually seem to be working. When SNMP messages are sent to the server nothing happens. However, in my app.publish folder there's an SNMPTrapper.exe application,and if I run that exe on its own, then everything works fine. For the time being I'm using a workaround so that the Onstart section of the code for the service basically just launches the SNMPTrapper.exe application, and when the service is stopped, it finds and kills the SNMPTrapper.exe process. At this point though, the service itself doesn't seem to be working/doing anything. It's essentially just a way to get the SNMPTrapper.exe application launched.
Does anyone know what the issue may be? In some of the tutorials I've read through they outline how to setup polling intervals for the service, but I don't think that would be applicable since this service will essentially just run constantly to listen for new messages, it won't need to check for anything at a regular interval.
Right now pretty much all of my code is executed in Sub Main() except for a few function calls.
Any help would be greatly appreciated.
You don’t state how you’re doing any of this. For a windows service you get two messages from the system: OnStart and OnStop. The job of OnStart is to set up all the required code to do the job, then exit. It doesn’t take part in the work so you need a Task or Thread setting up to do that. The Task or Thread should loop until it gets a message, passed by OnStop, that we’re done. If you want a service that you can test from the command line then your Main routine needs to do exactly the same setup, then wait for a key to be pressed before sending an OnStop.
(As an aside, you ARE remembering to start the service once you have installed it?)
I get an error message "an error has occurred while sending a request" when my UWP app tries to communicate with a WCF Service Application (that retrieves info from a database server). This error occurs when the app/service combo runs in Windows Mobile 10 Emulator and phone. On the other hand, this combo of app/service runs fine in Local Machine (my Windows 10 desktop PC). Seem like the WCF service may not be running when the app/service is running in the emulator or the phone. I would like to fix this problem if this is possible. If this is not possible, please suggest an alternative.
What I am trying to accomplish is to use a Windows 10 phone to connect to our database server (SQL Server) (all in local WiFi network, not through internet) to view or to update data in the database. Unfortunately UWP doesn't allow UWP apps to connect to the database server directly as stated in this web page:
https://code.msdn.microsoft.com/How-to-access-data-from-935e360c#content
According to that web page, I need to create a WCF Service Application as a middle-man between the UWP app and the database server. That is the reason why I need a WCF Service Application in addition to my UWP app.
Please note that I have tried the sample program in the web page shown above. Unfortunately, it has the same problem as my app.
As mentioned above, the sample program and my app both work fine in Local Machine (the database is in a database server that is not in the Local Machine). But both show the same error when they are running in Windows emulator or in a Windows phone.
I have tried to narrow this down by using a bare-bone WCF Service Application that doesn't connect to the database server to rule out the database connection has anything to do with this problem. The bare-bone WCF Service Application simply returns hardcoded test data to the UWP app. But it still has the same problem. This means the problem has nothing to do with database connection.
The bare-bone WCF Service Application is created using the WCF Service Application template. I have only renamed the classes (from Service1/IService to DbService/IDbService). Nothing to it.
The error is triggered in the GetDataAsync(...) statement in the example shown below. It is in OnLoaded() event handler of MainPage.xaml.cs of the UWP app:
private async void OnLoaded(object sender, RoutedEventArgs e)
{
try
{
RefDbService.DbServiceClient client1 = new RefDbService.DbServiceClient();
String sTestMsg = await client1.GetDataAsync( 12345 );
// The above statement triggers the error in Emulator or in phone.
this.lblDebugMsg.Text = sTestMsg;
}
catch( Exception ex )
{
this.lblDebugMsg.Text = ex.Message;
}
}
Thanks in advance for any help.
Jay Chan
My last message had a wrong URL (duplicated URL). The following has the corrected one:
I have finally created a small sample program (WCF service and UWP app) that actually works. If someone needs to do the same thing, you need to following this tutorial https://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx to learn how to write a WCF Windows Service Library (needs a host program) that works with console application, and then following this web page https://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx to learn the way to convert it into a WCF Web Service Application running under IIS and work with UWP. Remember to update the service-reference of the app whenever you change the configuration of the WCF service.
I have a very strange issue that i cannot figure out.
First i have a WCF service 4.0 done in VS2010.
the service have couple methods that return string array, datatable and such.
some of them use function from C++ dll throught [dllimport]
i made a test console to test everything. when i run the WCF from visual studio and use the generated path it works wonderfully.
now here is where it become strange. if i open my local IIS create a new application and point to my VS source code the WCF i can see it perfectly.
now using the http path from IIS local instead i refresh the methods all seems correct. But when i run my test app i can call any unction without any problem EXCEPT anyone using DLLIMPORT functions. they ALL crash and cannot trace even by tracing CES exceptions.
Doing line by line logging show that the exception is really on the call of those functions
the DLL in question is the same and the path is hardcoded for my computer since still in test phase and the folder is c:\DLL\mylib.DLL so nothing to do with shadow copy IIS/visual studio do when you actually run. also DLL reference by name withotu path even if it's in sys32 doesnt work.
Any clue ?
also. 32bit, changing app pool level right access on folder, full admin on machine already too. all tried but unsuccessful.
Edit: adding to all that since i haven't made this clear, it's not my first WCF real setup. i've already made alot of services before and deployed them myself (probably somewhere around 50-60 services). I am asking because i have never seen this issue before and i tried all tricks i knew and could find on the internet and resource people i know.
We have decided to incorporate the whole service in the WPF project locally since it work as long as IIS is not hosting. but this is really not a good thing as this data and work should NOT be done on client side but instead on server side. Right now it's fine since the software that need to use this is not released to public yet so it isn't critical.
Next option will be net TCP/IP windows service hosted on the web server if i don't find anything else.
We decided to go trough the trouble of having to hard code the logic in the main software and get away from web services for this issue. we will have to deal with updating, installing unregister and re register unmanaged DLL by hand somehow but at least it works.
we have added over 5 web services since that happen and no problem with them but again none of them use DLL imports.
Very frustrated with all of this, hoping someone can assist.
I had a Silverlight application and WCF working together without issue for a year. In order to get them working, I had some pain initially but finally worked through it with help. All of the pain came from configuration/security, 401's, cross-domain hell, etc.
The way I have everything setup is that I have a WCF service that resides in it's own application/directory and runs in its own application pool.
On the same web server (IIS7), I have another application/directory with the Silverlight application that points to the aforementioned service.
The server name (for this exercise) is WEBSERVER1. We've created a CNAME for it that is WEB1. In the past, if the user went to http://WEB1/MyApp/ or http://WEBSERVER1/MyApp/ it would work. Suddenly yesterday it started behaving badly. Normal users started getting the Windows challenge/response prompt (and even if they entered the info they would get a 401 error).
My WCF service runs in a site that enables anonymous access (and this has always worked).
My Silverlight application runs in a site that has windows integrated (and this has always worked), since I capture the Windows username when they connect.
For the record, I did create a NEW application pool yesterday with an ASP.NET application that runs in it. This seems to work fine, but there is a chance creating this new application pool and application/directory has caused something to change.
I have a clientaccesspolicy.xml in my wwwroot folder, as well as in the folder for each of the two applications above (just in case). I have tried to promote NTLM over Negotiate as a provider (as that worked for another issue I was having on another server).
After trying some changes, I can't even get the thing to behave the same each time I call it. Sometimes it will prompt me for credentials. Other times it will work, but then say it failed to connect with the WCF service with a "not found". Other times it will actually work fine, but only if I am using the actual server name and not the CNAME. When using the CNAME I always get the crossdomain error, even though I have the cross-domain xml files in every directory root.
This is a nightmare, and makes advanced algorithm analysis seem fun and easy by comparison. Did Microsoft realize how difficult they made this combination of (IIS7/WCF/Silverlight/providers/permissions/cryptic or missing error messages) to get to work??
I found a solution that appears to be working.
In this case, I had to change the authentication mode for the default web site (which hosted the clientaccesspolicy.xml file) from anonymous access to Windows Integrated. I don't understand why this worked for a year or so and then stopped, but it seems to have resolved it.
The new application that I had deployed yesterday was a standard ASP.NET web application, which I put in it's own application directory and it's own application pool, to ensure that it would not cause this sort of issue. I'm still not even sure if it did.
The way I resolved it was by trying to navigate from my PC to the actual http://servername/clientaccesspolicy.xml file, and that was giving me a 401 error. I switched from anonymous to windows integrated on that default website (which has nothing in it except for that xml file) and that resolved the permission issue. I then had to permission the actual AD groups to have read access to that folder (if not they got the user/pw prompt and could not get through).
With Visual stuido 2010, it's simple to set up SL4 to debug with an out-of-browser installed app. I followed the instructions from here and everything seems to set up fine. Debugging from the browser runs the program just fine, but running from the OOB program gives a different result. After starting, the screen will go blank and then hang forever. I have some concerns that it might be because of some of the technologies that we're using.
Firstly, there's a popup that happens because we're using WCF RIA Services (formerly .NET RIA Services).
"RIA Services will fail unless the silverlight project is hosted and launched from the same web project that contains the RIA Services."
This seems to just be a warning, but I have a suspicion that this warning might be telling me that RIA Services needs to have the .web project as its startup project.
We're also using prism and the error has an odor of a Prism error too. (something loading and then not ever appearing)
Has anyone else had any issues with OOB debugging in SL4? Is anyone else OOB debugging in SL4?
Sorry it's so vague. It's a complicated mess. The only message I see is the italicized popup warning. Then the window (which was previously showing the background of our application) just goes blank
There is currently a known issue with debugging an Out of Browser Silverlight 4 application when using F5 to launch the application from within VS 2010. The question I have is whether or not the application launches without debugging (-F5 or running it from the shortcut)? In the case of using F5, a dialog typically appears with the following error dialog “Unable to start debugging. A fatal error occured. For more details, please see the Microsoft Help and Support web site. HRESULT=0x80070018” and then the application appears to hang. In this case detaching allows the process to continue and then reattaching should allow you to debug the process.
If this is completely blocking or you’re trying to debug code running at startup (like the page startup event), one possible way to get around this would be to put in a call to System.Diagnostics.Debugger.Break, start the program and then attach when dialog pops.
This can be caused by the OOBA install being older than the version you are trying to debug. Remember, Silverlight OOBAs do not automatically update themselves to the latest version of the XAP file that may be available on the server. You have to update them yourself. If you get this error and you have included the auto-update logic in your app, just bounce out of VS, run the app so it auto-updates, then go back in and debug.
Alternately, you can uninstall the app and re-install it. That will ensure you are debugging against the latest VS build.
I ran into this same issue with VS 2008 and Silverlight 3. If I got it, I just jumped out and updated the app then re-ran it in VS and had full debugging.