Silverlight Socket Policy Not Working - c#

I am trying to implement a data push from a Windows Service to a Silverlight app. I have created a policy server which sends this policy file:
<?xml version="1.0" encoding ="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*" />
</allow-from>
<grant-to>
<socket-resource port="8400" protocol="tcp" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Using a TCP test tool I have verified that when I connect to port 943 and send the request, I receive back that policy file.
Also, using breakpoints in my policy server I have confirmed that the Silverlight app is reaching the service and seemingly the service sends the policy file without error.
I have also confirmed that my data push service is listening correctly on the above port.
However, somehow Silverlight's connection to my data push service is always failing with a WinSock 10013 Access Denied error.
The only thing I can think is that my policy file isn't correct, although as far as I can see it meets the spec. Let me know if you'd like me to post any of my other code. Any help would be appreciated.

It turns out my port was out of range. Silverlight can only connect to ports 4502-4534.

Related

The test form is only available for requests from the local machine

Why is it that for some of my web services, I get test forms, so I can see the generated XML data, but for other web services, I get a message saying "The test form is only available for requests from the local machine."?
Both times, I am connecting to the URL of the web-service from a client side browser and all web services are created with C#, .NET 3.5.
I googled for "The test form is only available for requests from the local machine."
There were many results, and the consensus is to add these nodes to the web.config file of the web service. I haven't tried this solution yet, but you can check to see if your web services that shows the test form remotely has this that have these nodes in the web.config. Or, you can add it to the web services that give this message and see if the test form starts appearing remotely.
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
Here are some of the search results
Stack Overflow: The test form is only available for requests from the local machine.
GeeksWithBlogs (archived on the Internet Wayback Machine): "The test form is only available for requests from the local machine"
Microsoft support: INFO: HTTP GET and HTTP POST Are Disabled by Default

How to start Azure worker roles and redirect the client to them

I am working on a game server running on the Azure cloud and I've hit a bit of a roadblock. The game itself is based around a series of worlds, each of which running on a different worker role and having separate terrain data. I however do not know how I can make the main worker role I use for managing those worlds to start the world roles and configure them to load the correct map. I also don't know how I can make sure that the client connects to the world requested instead of some random other world.
If anyone could link me to the correct APIs to do this that would be appreciated.
In your solution you can create multiple worker roles and create an endpoint for each role with a specific port (the same port cannot be used for different roles). Note that I'm using an input endpoint in order to have the endpoints load balanced.
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="CloudPathDemo" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-05.1.7">
<WorkerRole name="WorkerMainWorld" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="tcp" port="50000" />
</Endpoints>
</WorkerRole>
<WorkerRole name="WorkerWorld1" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="tcp" port="50001" />
</Endpoints>
</WorkerRole>
<WorkerRole name="WorkerWorld2" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="tcp" port="50002" />
</Endpoints>
</WorkerRole>
<WorkerRole name="WorkerWorld3" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="tcp" port="50003" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>
Now, if you want your client or your 'main' worker role to connect to world 3 for example, you would send the tcp requests to mygame.cloudapp.net:50003 for example.
If you want to make the 'terrain management' somehow dynamic you could work with topics and subscriptions. Let's assume each WorkerRole has 1 topic, and each instance is 1 subscription. Then you could send a message to a specific topic saying which worlds should be provisioned on that WorkerRole, and each instance of that WorkerRole will receive that message and do the necessary provisioning. Ofcourse, you'll need to take into account that instances might be added later (when you scale up), so these instances will also need to know which worlds should be provisioned (by reading the list from table storage from example).
My recommendation would be to create a master/controller that is an endpoint (proxy if you like) for the worlds. All connections come to it and it then routes them directly to the back end world specific server. This connection can be very thin (I'm thinking just an IP tunnel once the connection has been established), so it won't add much latency to it.
Now there's a couple gotchas with this approach.
The proxy can only handle a limited number of active connections. So you have to have a way to monitor this and route traffic to a secondary proxy/relay. Windows Azure's built in load balancer should do nicely for this, you just need to monitor active connections and use that info to control your scaling behaviors.
Additionally, idle connections will be killed by the Windows Azure load balancer, so your proxy will need to be able to detect when a connection has been killed so it can free up those resources to service another connection.
The upside to this approach is that if your world servers go off-line or are moved around (and they will be at some point), the proxy can detect where the workload has moved and shift connections accordingly, making it seemless to your external users.
Now there's one other approach to all this that would also work. The Windows Azure Service Bus relay. Each "world" server would have its own endpoint on the service bus and when a client asks to connect, it comes to the controlling "proxy" and gets the endpoint for its requested server. You can take this one a step further by enabling hybrid connections which will encourage the client and the server to negotiate a direct connection and thus reduce any relay latency. And the service bus endpoint, since its a published location, resolves any issues with machine specific addressability.

WebRequest.Proxy - What is the default value

Background: We have a service installed at a remote site that has started failing to call an external webservice. According to the network\support engineers on site no proxy should be required, but when attempting to execute the WebRequest an exception is returned:
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
The exception is relatively self-explanatory, but looking at the code, no Proxy is specified in the call to the WebRequest and no proxy is defined in the app.config file.
Referring to the MSDN documentation for WebRequest.Proxy:
"The IWebProxy object to use to proxy the request. The default value is set by calling the GlobalProxySelection.Select property."
and then referring to the documentation for GlobalProxySelection.Select:
"Gets or sets the global HTTP proxy."
And given that GlobalProxySelection.Select is not set anywhere in the application, where does the default value come from? And are there any other global config files where the global HTTP proxy may be set?
You have to set the proxy manually. You can do it by doing the following, if you want to use the Default system proxy. (Internet settings in windows)
myRequest.Proxy = WebRequest.GetSystemWebProxy();
You are getting the error because your network is blocking access to the server directly without using a proxy.
While this doesn't solve your problem directly, can I recommend trying a <defaultProxy /> element in your app.config / web.config under <system.net> with useDefaultCredentials="true" - this may well get your application authenticating through the proxy and therefore not requiring a special bypass rule at all.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>

The remote server returned an error: NotFound. Silverlight + WCF

I'm trying to call web service for few hours.
I have added clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
and crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>
to root directory of my web site.
Web service is called from IIS, and it's working here.
But when I'm trying to call my wcf web service from silverlight application I get this error:
The remote server returned an error: NotFound.
This is log from Fiddler:
a:InternalServiceFaultThe server was unable to process the request due to
an internal error. For more information about the error, either turn
on IncludeExceptionDetailInFaults (either from
ServiceBehaviorAttribute or from the <serviceDebug>
configuration behavior) on the server in order to send the exception
information back to the client, or turn on tracing as per the
Microsoft .NET Framework 3.0 SDK documentation and inspect the server
trace logs.
This is code, when I get an error:
public int EndUserExist(System.IAsyncResult result) {
object[] _args = new object[0];
int _result = ((int)(base.EndInvoke("UserExist", _args, result))); //Here
return _result;
}
What am I doing wrong?
Look in your web.config for this text: IncludeExceptionDetailInFaults
set that to true. Then run your service request again and watch Fiddler this time it will tell you what you need to know.
May be anything from a SQL error to a null reference. :-)
All right ;)
Now it's working.
I turned on debug in web.config so I got exception message in Fiddler.
I need to set identity user in pool on IIS for sql database.
In your mobile device, go to wifi settings and edit current wifi connection.
Set proxy "Automatically detect settings".

silverlight: clientaccesspolicy.xml any localhost?

I have an (otherwise) functional clientaccesspolicy.xml file that is not working correctly for requests from localhost unless a specific port is given. Below is my file installed on my development server that functions properly for any requests except those coming from any localhost. It works correctly for locahost requests on port 11712, but won't accept any others. This is what I would expect... no problem so far...
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*.myDomain.us"/>
<domain uri="http://localhost:11712/"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
I want to completely open up access to any localhost regardless of port. so if I change the domain node thusly:
<domain uri="http://localhost:*" />
or
<domain uri="http://localhost*" />
or
<domain uri="http://localhost"/>
do not work, failing as a cross-site error. The only way localhost access works is if I specify the exact port, which means that I'd have to specify any potential client app in the list (or require them to use a specific port).
alfonso pointed me in the correct direction. According to Microsoft, the clientAccessPolicy.xml file does NOT allow wildcards in the port:
Silverlight does not support wildcards for the port field in
clientaccesspolicy.xml, and neither does it support the to-ports
attribute in the crossdomain.xml. Can you give us a little more
information so we can think about adding support for this in the
future please - why do you need to be able to launch your XAP from
multiple different ports?
from: http://forums.silverlight.net/p/48275/128264.aspx

Categories