I'm writing a Silverlight application that needs to interface with a server via GET/POST requests. My code looks like the following:
Uri serviceUri = new Uri(my_URI);
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(OnRequestComplete);
client.OpenReadAsync(serviceUri);
However, when the callback function is called, I am getting a System.Security.SecurityException. I've read multiple questions on here from people with similar errors, however all of their issues seem to stem from cross domain issues while debugging. When I run my code, it runs with http://localhost:... as the domain, so that shouldn't be the issue I don't think. Here's the full error if that helps at all:
{System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)}
Thanks for any help. This has been a very frustrating issue.
UPDATE:
I screwed around with it a lot and eventually got everything to work. Not 100% what did it though... I ended up copy/pasting the clientaccesspolicy.xml and crossdomain.xml files everywhere imaginable, created a new Silverlight project and copied everything there, along with a few other things. If anyone else runs into this problem, that's about as much advice as I have to give :/
I think it is still violates same-origin policy because the port numbers don't match: i.e. the XAP uri's port and the my_URI port do not match. And hence the System.Security.SecurityException. Could you try hosting the my_URI relative to your XAP.
Or even better, can you try interacting with the server using WCF.
Related
Based on an example I found, http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service, I'm implementing a SignalR host server within a Windows Service.
It all works fine but if I try:
SignalR = WebApp.Start<SignalRStartup>("http://*:8080/");
I get an unhandled exception of type `
'System.UriFormatException'` occurred in System.dll
Additional information: Invalid URI: The hostname could not be parsed.
It works fine if I use
SignalR = WebApp.Start<SignalRStartup>("http://localhost:8080/");
Probably a dumb assumption but based on the article I took this from, I assumed the *:8080 syntax would work. My question is, have I missed something or was the article incorrect and this format won't work?
So, the + does work... (and yes, I feel dumb) During my testing I think only 1/2 the time I remembered to run as administrator, which lead to bad test results since it was failing because of trying to open the port, and not because of the address.
I got clued into this by reading the Owin/Katana source code linked by #DigitalD. Turns out that not only does it support the + syntax, there is a comment from the code saying it's assuming it...
http://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Host.HttpListener/OwinHttpListener.cs
// Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash.
Have you tried removing the port number from the URI?
try
http://localhost instead of http://localhost:8080
I am working with a program that is meant to publish to and read from an existing TIBCO EMS hosted on a server separate from the program. I have referenced the sample code provided with the TIBCO installation, resulting in a big chunk of the program. Here is the code snippet that I am having troubles with:
1 QueueConnectionFactory factory = new TIBCO.EMS.QueueConnectionFactory(serverUrl);
2 QueueConnection connection = factory.CreateQueueConnection(username,password);
3 QueueSession session = connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE);
When line 1 runs, it goes through alright. When line 2 runs, it goes through alright, however, the connection object is null, resulting in an error during line 3 where a NullReferenceException occurs.
I would have at least expected that line 2 would return some sort of error to show that the request timed out, the credentials were wrong, the url is inaccessible, or at least something to let me know what the issue is, but there is nothing like that, until it hits line 3.
Does it have to do with the configuration of my application? All I have done to get this working is include the TIBCO.EMS.dll as a reference and worked with the code from there.
Could it have something to do with the fact that I am connected to a VPN that requires a proxy? If so, how can I set up that proxy in my code?
Any help would be greatly appreciated. Thank you.
The issue was that I was using the wrong version of the .NET framework to work with the Tibco integration. The version I was using was farther along than the original.
It would think that your server URL is incorrect.
try different urls maybe like tcp://localhost:7222 (where localhost can be the IP/Name of the remote server)
install EMS locally on you workstation and see if you can connect to it. (Default admin with no password)
I have been been developing a platform using ZMQ (2.2) as the main communications layer. Earlier this week I decided to take the advice on the zeromq website and upgrade to the latest stable build 3.2.2
However after going through the pain of updating to the new API I was seriously disappointed to discover that there seems to be a problem with the clrzmq binding in that it fails to load the libzmq library on Windows XP (SP3) machines. I keep getting a SEHException exception?!
I was just wondering if anyone out there has had the same problem and if there is a workaround (or even better a fix) for it?
Cheers
:)
EDIT
Just to clarify, the library is loaded fine, I know this because the context is created without any issue. The problem occurs when the CreateSocket method is called on the context... see code snippet below
ZmqContext context = ZmqContext.Create();
ZmqSocket socket = context.CreateSocket(SocketType.REQ);
After adding tracing as suggested by Jakob, I get the following output
Assertion failed: Connection refused (..\..\..\src\signaler.cpp:310)
Any Ideas what this means?
EDIT
I should also mention that this issue does not happen on all the XP machines, only some of them. I have been trying to figure out what the difference is between the machines that work and the ones that don't. Without knowing this it would be far too risky to upgrade and release into a production environment.
Looking at the example you provided, you are binding to a REQ socket (Request, i.e. client socket), and also binding the REQ socket using wildcards. I am not sure how this will play out, but to me it does not make sense. I do not think this is supported but I cannot find or remember any documentation about binding to a REQ socket. Likely strange things will happen.
The REP (response) socket is the "server" end of a REQ/REP setup (request/response), where you bind the server side using a REP socket to an endpoint, either explicitly specified "tcp://127.0.0.1:5555" or using wildcards, e.g. "all interfaces", "tcp://*:5555". The client side would then connect using a REQ socket to an explicit endpoint address, "tcp://127.0.0.1:5555", no wildcards.
The server would do this:
ZmqContext context = ZmqContext.Create();
ZmqSocket socket = context.CreateSocket(SocketType.REP);
socket.Bind("tcp://*:5501");
And the client this:
ZmqContext context = ZmqContext.Create();
ZmqSocket socket = context.CreateSocket(SocketType.REQ);
socket.Connect("tcp://127.0.0.1:5501");
Apart from those issues, you should also make sure the firewall is not blocking and make sure the port is not already in use (using for example the NETSTAT command).
For ZeroMq addressing rules, see the zmq_tcp API documentation, and for the socket, see the zmq_socket API documentation.
I've been having trouble querying a web server for information from my Windows Phone 7 app, and from my research, I've traced it back to MaxBufferSize/MaxReceivedMessageSize being too low. The problem is, I can't figure out how to change it. Every search result I find talks about the application being a WCF app, and to change the binding in ServiceReferences.ClientConfig. The solution from this post gives this example:
1. edit the ServiceReferences.ClientConfig to accept a large buffer.
<binding name="BasicHttpBinding_MosaicService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
However, I'm not using a WCF app, and I don't know what the equivalents of the above, and ServiceReferences.ClientConfig are for a regular WP7 application. Can anyone give me some help with this? I've done my best to figure it out myself but I'm getting nowhere.
For reference, in case someone else is having the problem I was (it took a really long time to figure out that this may be the problem), this is what is happening to me: I'm getting a WebException with the message: "The remote server returned an error: NotFound" thrown. And the relevant section of the stacktrace is:
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
I'm not sure how you went from the error message "The remote server returned an error: NotFound" to thinking that your client can't handle the size of the response. Much more likely, the error message is correct and the URL you are requesting can't be found. Drop a breakpoint in your code where you kick off the request. What is the RequestUri property set to on your HttpWebRequest object? Copy that URL into a browser and you'll more than likely see that you get a "page not found". Fix your incorrect URL and all will be well.
I had an XMLDocument loading a document from a server with no problems till, almost randomly, I started getting a connection refused error.
It also doesn't matter what host I put in, whether it's a legit one or unresolvable. It always gives the same result.
Here's the code:
XmlDocument doc = new XmlDocument();
doc.Load("http://doesnotmatterifIresolveornot.com");
And here is the error:
{"No connection could be made because the target machine actively refused it 127.0.0.1:8888"}
I've turned off any applicable firewalls I can find in Win7, but it's weird cause it happened while I was testing it.
Find out why it's trying to go to 127.0.0.1:8888.
My guess is that for some reason, it thinks that's your HTTP proxy. Did you run something like Fiddler recently? Fiddler runs on 8888 and changes your default proxy settings - maybe they got stuck incorrectly?
Look in Control Panel, or in the Internet Explorer settings.
Are you serving your XML document using IIS? If so, you may need to add a mime-type definition to IIS to serve XML files. This article should help with that (if it is indeed the problem).
you may also try the HTTP loader to get a more detailed picture of what the server is responding with (HTTP headers, in particular, could be useful for troubleshooting).
I suspect the primary issue is that you're trying to connect to a socket (server + port) that the server isn't configured to listen on -- that means you'll get this error regardless of whether or not the URL resolves, since the server isn't configured to deal with a socket connection of the sort you're sending it.