silverlight error - the opreation is not supported for a relative uri - asp.net

I've just started developing silverlight applications. I've created a webserivce in my asp.net project. Now, when I try to connect to it through my silverlight project I receive the following error:
"the opreation is not supported for a relative uri"
I am using the following url -->
http://192.168.1.2/MyWebsite/SubVersionedHistory.svc
I can find the class and its methods, but I receive this horrific error when I add it.
Thank you for your help and advice,
Vondiplo

I don't think you're alone in hitting this problem. I hit it today with VS2008SP1 + SL2 trying to create a Service Reference for an ADO.NET Data Service. First time I've hit the error.
Others have detailed similar experiences to reach this error:
http://silverlight.net/forums/t/87535.aspx
http://silverlight.net/forums/t/56629.aspx
It's not entirely clear at this point if the issue is with the IDE "Add Service Reference" dialog or something specific in the services causing this error. In my case, however, my code still worked despite the error message. I simply passed the URL to my service in the constructor of my DataService proxy client, like this:
var context = new DataServiceContext(new Uri("NorthwindDataService.svc", UriKind.Relative));
Summary point: Just because you hit this error in the IDE, your service reference may still work. Give it a try and let us know if you're seeing errors at run time.
Hope that helps.
[UPDATE] Based on some other advice I've found and tested, you can also try:
deleting your Service Reference
deleting your ServiceReferences.ClientConfig file
saving your solution
and then closing and reopening it in VS.
The simple act of closing and reopening your project has been shown to fix several problems with the Add Service wizard. Re-run the Add Service Ref wizard and you may have better luck. I personally tested this solution on a project today and can confirm it works. Hope that adds extra help to finding your solution.

You should be more specific about your problem. For example, are you having this problem when adding the reference or when you actually try to consume the service?
It sounds like you need to be using a full path, including the "http://" but that is just a shot in the dark based on the error message you provide.
[edit]If you are using the built in ASP.NET server instead of IIS then be sure you set a specific port number and use it in your path. For example, I have used http://localhost:4940/MyService.svc for testing[/edit]

Maybe this response can help you
You cannot use AbsolutePath, You need to use AbsoluteURL. Build your URL this way:
Uri url = new Uri(App.Current.Host.Source, "../settings.xml");client.DownloadStringAsync(url);
http://silverlight.net/forums/p/28912/95541.aspx
HTH
Braulio

Check the ServiceReferences.ClientConfig
if there are multiple endpoints there you will get this exception. one thing that can cause this is referencing a service using casini, later switiching to IIS express and rereferencing the service.

Related

Unable to add reference to third party WCF Service using Visual Studio

I recently received an updated integration document from a third party web services provider. One of the changes indicated that there are updated services that are located at a new URL.
I proceeded to delete my existing reference in my .NET 3.5 console application (VS2012) and attempted to add a new one pointing to the updated URL but was unable to do so due to the following error and die disabled "Add" button:
I subsequently tried to restore the reference to the old URL (which worked a mere month ago when I initially added it) but that to gave the same error.
I did a bit of googling and found the following posts that were not very encouraging:
Can't add Service Reference
Mixing Add Service Reference and WCF Web HTTP (a.k.a. REST) endpoint does not work
Don’t use “Add Service Reference”!
The first link simply repeated my problem statement. The second suggested there is no hope for me and the third is of no relevance since I do not control the server side component.
I was hoping someone with some more WCF experience possibly point me in the right direction. I suppose my question is twofold:
1: Is this something I am doing wrong on my side or can it be a problem with configuration on the third party server?
2: Is there any way I can reasonably add a reference to those services in my project without using "Add Reference" in VS, using the WSDL which I am able to download?
Edit: Just to calrify, the URL resolves and I can see the service controls and descriptions in both my browser and the VS window where you attempt to resolve the WS but the ".../$metadata" part in the error message above is not part of the original URL I entered. original URL which resolves fine is http://service.somewhere/service234/thing and the error refers to http://service.somewhere/service234/thing/_vti_bin/ListData.svc/$metadata

SignalR $.connection not defined, intermittent successful definition on some PCs

I have a MVC5 project using signalr to perform updates to a list. Inside script.js, there is a variable link to defined as var link = $.connection.hub. There is also a bundleconfig file to load the dependent scripts, signalr/jquery and jquery in the proper order of course.
The script /signalr/hubs is loaded in from the html manually.
bundles.Add(new ScriptBundle("~/bundles/signalr").Include(
"~/Scripts/script.js",
"~/Scripts/jquery.signalR-2.0.2.min.js"));
When the VS 2013 Web project is run, it works fine until the project is copied over to another PC that it does not work as intended. The variable link is undefined as $.connection is undefined too ($ is defined though).
I presume that jquery.signalR-2.0.2.min.js is not read or executed at all.
Questions:
Might this have anything to do with the environment of the PCs? (Windows 7 is OK, Windows 8 is not OK)
What could prevent jquery.signalR-2.0.2.min.js from running?
Does creating a new View/Controller play a part in the error (creating a view, using a layout page)?
Please see similar question: SignalR and MVC bundle as it shows how to add SignalR into an MVC bundle. I think their answer should help solve your problem.
I would comment instead of answer, but I don't have enough reputation.

WCF Update Service Reference fails

When trying to update service reference I get following error -
I read guide-line at many places that we should checkin only Reference.cs. But I have checked in other ServiceReference files, (like wsdl, xsd etc) as well.
Can this be a cause of UpdateService Reference to failure?
Sounds like you are targeting the wrong framework in your project or you need to completely delete the service reference and re-add it instead of trying to update.
Check this link out
http://connect.microsoft.com/VisualStudio/feedback/details/542789/could-not-resolve-mscorlib-for-target-framework-netframework-version-v4-0-this-can-happen-if-the-target-framework-is-not-installed-or-if-the-framework-moniker-is-incorrectly-formatted
Good Luck

MessageBox.Show() not working in ASP.NET

I am trying to display some text using MessageBox.Show as shown below in a page_load event in ASP.NET. Before anyone jumps on the case why I am using it in ASP.NET, the use is for debugging only on my own dev box for a special need. There's a reference to System.Windows.Forms in the app.
I used it a few years ago so I know WinForm's MessageBox works. I am using .NET 4.0 and VS 2010. I don't think anything related to this function has changed.
MessageBox.Show("Message", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); //used also ServiceNotification option
Any ideas why the message box doesn't display? I have only that line in the code.
ADDITION:
I am VERY AWARE of the message box thing implications. It's a temporary thing for debugging only. The line won't go into production. I have no access to javascript. Please put your thought into why it doesn't work instead of why I shouldn't be using it. I have used it before in 2.0 and it does work. I want to know if the newer .NET changed anything or I misused the option.
Direct Answer: it works in Visual Studio's web server , not in IIS.
The web application is hosted in a process that does not have a desktop, so you cant see any messageboxes.
#Tony, if you add System.Winform.dll to your rference, then you will be able to call message box.show at you development machine. But when you deploy it to some live server it will not work. So alternatively, you need to use javascript alerts. For this you can use this
private void ShowMessage(string message)
{
ScriptManager.RegisterClientScriptBlock(control, GetType(),"key","string.format("alert('{0}');",message),true);
}
Back in .Net 2.0 days, you could do this by including system.windows (I think) in your using statement.
Then, in the method, it would be system.windows.forms.Messagebox.show("foo");
I won't presume to tell you "yer doin it wrong"...
Just be aware that this will only show up on the server box, and could cause issues in a production environment.
The alert() is better, and console.log() is even better.

ASP.Net MissingMethodException - "ctor" method not found

We are getting intermittent problems on a production server that we cannot recreate.
There are two very strange things about the issue. Firstly it's a method not found error on the constructor (ctor) for an exception handling helper class and secondly we have custom errors switched on for remote users and this property is being ignored.
The detail of the error is:
Server Error in '/MyWebsite' Application.
Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
Exception Details: System.MissingMethodException: Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
The stack trace is pretty unhelpful.
My thoughts are that there may be an out-of-memory error or something like that that is killing the page. When the exception handling code kicks in it tries to create an exception object which fails for the same reason giving this error.
However this is wild speculation. We are waiting for the event logs to see whether anything is amiss with the server but in the meantime does anyone have any thoughts or suggestions?
UPDATE:
It has proven difficult to get information out of the team responsible for the production servers but I have managed to find out that as far as load balancing is concerned, this site is currently only running on one server (this can be made to switch over onto another if necessary). Given that this is an intermittent problem and there is only one server involved, then I find it difficult to believe that this could be an assembly issue. Surely if it was then the problem would occur every time?
If you see this error happening on a site that has custom errors turned on, then the error is happening in the custom error handling routine itself.
From the look of the .NET error message it appears that your routine is expecting a constructor that accepts an exception by reference - your comment above shows a constructor that accepts by value.
Check carefully that there isn't a stale version of an assembly in your system somewhere. These can lurk in the Temporary ASP.NET Files folder; you'll need to do an "iisreset /stop" before you can clear them out.
In that regard it's always a good idea to make sure that AssemblyInfo.cs is set up to automatically stamp version numbers in some way. We have our version numbers tied to our source code repository system and CI build box so we can tell exactly what was in what assembly really easily.
I would use elmah: http://code.google.com/p/elmah/ to hopefully give you a bit more insight into the issue. It is free and can be used on an existing site without any recompilation. Try it - and post back if the issue is still happening.
As others have also mentioned, I would suspect that your site is somehow using an out of date version of an assembly. Something you could try doing is a full Precompile of your site before deploying to your production server. This ensures that ASP .Net doesn't dynamically compile the site on the fly, and therefore should mean that it's using completely up to date code throughout.
Do you have a no parameter public constructor defined for MyExceptionHelperClass in your code? Or is the class meant to only have static methods, in which case it should be a static class.
public class MyExceptionHelperClass()
{
public MyExceptionHelperClass() { }
}
Unfortunately, this may be one of those cases where the error message is of little to no value. In my experience, this general class of exception may be the result of either a configuration issue or bad logic aroung threading/app domains. For example, I have seen similar issues upon attempting to load the same assembly into an app domain more than once.
You mention that this is difficult to reproduce. If it's only happening on one server in the production farm it's more likely to be a config issue (with that machine). If it's happening on more than one server than it could be either config or threading.
It might be worth spending some time looking at the larger code base around the areas mentioned above. The root cause may not be in this class. Good luck!
I think it's a Framework issue with keeping compiled versions consistency. It's common to see same sort of errors while updating site sources repeatedly. Just try something like
net stop iisadmin /y && del /q /f /s "%systemroot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*" && iisreset
I encountered this exception today on a webforms page. I found a solution, but I'm not sure why it worked.
Nest the code behind in a 'Namespace [YourNamespace]' tag.
Add the namespace to the html Page tag's Inherits property in the aspx page 'Inherits="PathStart.YourNameSpace.ClassName"'.
Rebuild
Navigate to the page again and you should not encounter the exception.
After following the steps above I reverted the changes and did not re-encounter the exception.

Resources