silverlight: clientaccesspolicy.xml any localhost? - c#

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

Related

WCF Client Message Format c#

I'm creating an application that consumes a WCF web service. When I test a certain operation in SOAP UI, it works, however, when I test in VS2017 console app, I receive an error:
"The content type text/html;charset=UTF-8 of the response message does not match the content type of the binding"
I used Fiddler to grab the request from my console app, and I've narrowed the issue down to some of the formatting in the SOAP request. When I format my console app request to match the request Fiddler generates, it works. There are prefixes that are defaulted in my request that seem to be causing the issue, as well as xmlns declarations. I need to know how I can modify these parts of the request to conform to the web service which I have absolutely no control over (major corporation).
The prefixes s and h need to change to different values. I took this request and put it into SOAP UI, swapped the s and h throughout to match how Fiddler is passing in the request, and it works. I also had to move xmlns:h up to the Envelope level. Is there something I can change in my config file? Is there something with Message Contracting that I can easily implement? I need to be able to format this correctly, but I'm not sure what the best way would be.
BAD:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:FooListHeader xmlns:h="http://foo.foo.com/Hello" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<h:FooList>
<h:FooStatement>
<h:Title>Foo</h:Title>
<h:Value>123</h:Value>
</h:FooStatement>
</h:FooList>
</h:FooListHeader>
</s:Header>
<s:Body>
<GetFooRequestType xmlns="http://foo.foo.com/Hello">
<MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ConFooRequest/>
</MessageRequest>
</GetFooRequestType>
</s:Body>
</s:Envelope>
GOOD (how can I convert above bad example to this good example below in my app?):
<soapenv:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:foo="http://foo.foo.com/Hello">
<soapenv:Header>
<foo:FooListHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:FooList>
<foo:FooStatement>
<foo:Title>Foo</foo:Title>
<foo:Value>123</foo:Value>
</foo:FooStatement>
</foo:FooList>
</foo:FooListHeader>
</soapenv:Header>
<soapenv:Body>
<foo:GetFooRequestType xmlns="http://foo.foo.com/Hello">
<foo:MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:ConFooRequest/>
</foo:MessageRequest>
</foo:GetFooRequestType>
</soapenv:Body>
</soapenv:Envelope>
Service Reference Image
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="foo" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://Foo.foo.com/foo/foows.svc"
binding="basicHttpBinding" bindingConfiguration="foo"
contract="Service1Reference.IFooServices" name="foo" />
</client>
</system.serviceModel>
</configuration>
Everything I can find on the internet about this topic mostly revolves around the service side of things, not the client side.
The company has provided me with a .wsdl file and an XML reference file. I'm not quite sure what to do with the reference file, but I have loaded the .wsdl file directly under "Add Service Reference" in my application. I could not discover the service using the endpoint like I have in previous projects that I have worked on, so I had to store the file locally on my PC and specify the path to it directly when I added the service reference. Again, I am not able to discover the service using the typical ?wsdl address most likely due to service config settings for security purposes. Thanks so much for any responses!

Post Image to WCF Service From Fiddler

I have been working on WCF Services. I have a service that accepts a few parameters including Image. Here is my Request XML:
<?xml version="1.0" encoding="UTF-8"?>
<GPProcess xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Action>
<Device />
<GenopalAuthorization />
<P1x>0</P1x>
<P1y>0</P1y>
<P2x>0</P2x>
<P2y>0</P2y>
<PalletName />
<Picture i:nil="true" />
<PictureShare>false</PictureShare>
<PictureURL />
</Action>
</GPProcess>
The problem is that, I want to test this Web Service on Fiddler. I need help that how can I post an Image to Web Service through Fiddler? and what should be the content-type?
With Best wishes
It might be better to create a proxy class to call your service and build a simple client that uses that proxy. You can then monitor the traffic between the client and the service using Fiddler...

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.

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 Socket Policy Not Working

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.

Categories