Silverlight, deployment, ports, cross domain policies, & endpoints - silverlight

I made a simple Silverlight app, with a web service calling a database, and got it to work on my development computer.
When I published the web service project to IIS, on the same computer, and accessed the Silverlight app from IIS using http://localhost/SilverlightTest/, I could see the Silverlight in the page, but the call to the web service was not working.
So I added the file clientaccesspolicy.xml in several places. All of the instructions say to put it in the root directory, so I tried:
c:\inetpub/wwwroot\ Did not work
c:\webs\SilverlightTest\ This the folder to which I published the web service project, including the xap file. But did not work
c:\webs\ Just a guess, but that did not work.
Then, in VS, I added the file to the web service project, and that added it to the folder where the web service project is stored c:\work\Silverlight\TestWCF\TestWCF.Web\ . When I opened the page in Firefox from IIS, the call to the web service now worked. Apparently, the Silverlight application is calling the web service in my development folder, not the service in the IIS virtual directory c:\webs\SilverlightTest\ (He call to the web service did not work when I opened the page from a different computer in the workgroup)/
Why would the Silverlight application call a web service in a development folder? Shouldn't the web service be in the virutal directory to which it was published? How can I resolve the confusion?
Here is the configuration in my ServiceReferences.ClientConfig file
<client>
<endpoint address="http://dellnov2006:2753/SimpleWCF.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISimpleWCF" contract="SimpleWCF.ISimpleWCF"
name="BasicHttpBinding_ISimpleWCF" />
Any help, explanation, or pointers to relevant articles would be greatly appreciated. An article explaining how Silverlight apps call web services would be greatly appreciated.
Thanks
Mike Thomas

In your config file, the endpoint address is http://dellnov2006:2753/SimpleWCF.svc
So it seems that you are trying to connect to that address.
Before you publish the application you must modify that address to http://localhost/Service/SimpleWCF.svc or something to point exactly to your service.
The clientaccesspolicy.xml must be in **c:\inetpub\wwwroot** But you need this file only if you will access the service from different host that it was downloaded. I don't think you need it in your case, if you want to use localhost on the local iis.

The address in the ClientConfig is the address of the service you "Added Service Reference" against. As you noticed, it's not a relative path. To overridde this behavior, specify the URI of the address in the constructor of the Service client.
Also, you really need Fiddler. You'll love it. It helps with these issues as well as cross domain issues.

Many thanks djjoyro. You were right. Changing the config file to:
endpoint address="http://MachineName/SilverlightTest/SimpleWCF.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISimpleWCF" contract="SimpleWCF.ISimpleWCF"
name="BasicHttpBinding_ISimpleWCF"
worked, and without a client access policy file. This also worked when I accessed the Silverlight app from other computers in the workgroup.
I also tried using localhost instead of the computer name, but I did have to use a clientaccesspolicy file, and I could not access the web service when using other computers in the workgroup.
There is a lot more I need to know about this, but at least deployment is now working after several days of struggling.
Mike Thomas

Late to the party, but I will add that if your binding address includes a port #, then you are still using the Visual Studio web server. http://dellnov2006:2753 is a dead giveaway that you still using the VS web server and not IIS as you intended.

Related

Silverlight app - service URL cannot handle IP address

I have a Silverlight app that run on a single server which also hosts the web service used for data access. This is a Service Reference in the project. A common issue is that someone browses to the app using an IP address rather than the machine name. This breaks because the app thinks this is a cross-site violation.
To access the web service we create a System.ServiceModel.ClientBase and assign is an address in the web.config file. So locally in dev this is localhost:xxxx, and in production is it the machine name. Or we could set it to the IP address, but then everyone would have to go to the app using IP address only.
Is there a good way to do this? One issue is that some people access the app internally where the machine has a good name, while others access it through a VPN where they may need to use IP. I would like for both to work.
FYI I had this same issue. silverlight application and wcf service running on same server, but when application is started using an ip address vs. application url, then cross domain problems occur. evidently these urls/ips are not resolved/matched locally so to the silverlight application, they look like different domains. My app is running as an application and couldn't be moved to root of iis web site for technical reasons which is required for a clientaccesspolicy.xml file or crossdomain.xml to work properly.
I solved it by adding an entry into the hosts file on the server with the ip address and name of the domain. This looks a bit strange since we are on the server pointed to by the ip address and the domain/machine name but it works.
Adding this locally in the hosts file evidently redirects all requests for the ip address to the server PRIOR TO making either the call to get the silverlight application or the call the wcf service, so they look the same no matter whether the application or the service is called using an ip address.
Hope this helps anyone else in the future.
FYI - this does not work with VMs
We use VMs for some functionality and I have found this just doesn't work when running clients from the VM. The VM manager must do something to the request before passing it through. Just thought I'd mention this for future use.
Have you tried creating a clientaccesspolicy.xml file?
http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx

My silverlight application is still trying to connect to localhost after being published to a remote server

I'm developing a silverlight application that uses a web service. It works just fine when I run it on my local machine but when I publish it to a remote server, it fails because it is looking for a a crossdomain.xml policy at localhost:4689 instead of the websites root directory. How do I fix this?
Thanks for the help!
When you add the service reference, the host--in your case, localhost--is included as part of the generated code, and is the default endpoint when you create the service client on the Silverlight end with no constructor parameters.
Use the constructor overload of the service client class that accepts a Uri parameter to specify the correct hostname (and path to the .svc file) on your production server.
You need to edit your ServiceReferences.ClientConfig because when you deploy your project it's still using the endpoint address of your local computer.

WCF Silverlight crossdomain problem

I have several WCF services.
When I check them on the server (example: ServiceTest.svc?wsdl), than I see an xml file with info about the wcf service. So the services works fine.
I have a Silverlight application on a different server.
I get the 'famous' crossdomain error.
When I place a clientaccesspolicy.xml in the directory with the WCF services, the problem remains.
Is it possible that with shared hosting, the security isn't high/low enough?
thanks,
Filip
The XML file must be placed in the root of the domain. Usually you have to put them into the inetpub/wwwroot folder, instead of into the folder with the WCF services.
Depending on how your provider implemented the shared hosting, I'm afraid you'll have to ask them to support cross domain access and put the XML files into the root.
I am not sure but I think it also could work to register your own domain that points to the folder you want to use as root, and put the XML files there. The clients must then use the server URLs with your registered domain of course.
One of the best tools for issues like this is Fiddler(or some other web debugging proxy). Looking at the network calls, you can see the address where the browser is looking for the clientaccesspolicy.xml file and then make sure you drop the file at that location. If you're not seeing this call or you're seeing it and the file is already there, you can move on to other issues (a bug in the webservice or the calling code).

cross-domain problem

I am using a silverlight with wcf and when I use the .web project then it runs but when use the silver light project to run the following exception throws:
An error occurred while trying to make a request to URI 'http://localhost:9000/Services/BLWCFSvrc.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.
I want to use the silverlight project to debug my code
Thanks in advance
In order to access network resources from Silverlight, the domain hosting the resource must provide a client access policy file; this is designed this way for security reasons. See here for details: http://msdn.microsoft.com/en-us/library/cc645032%28VS.95%29.aspx
I think your problem is different that just having the clientaccesspolicy.xml, the fact that it runs under the web project, means that you are delivering policies, if you have those added as seperate files under the web project then they wont be deployed when you run the SL3 app seperately, but im sure you figured this out and you're delivering the policies via WCF using webHttp binding (RESTful style), if not, you should.
I think the problem is that when you run the webproject, it builds to your local IIS and executes from there, IIS will allow the SL3 app to communicate with ports/addresses different from the ones that the site is hosted on
when you run SL3 app natively, VS2008 auto generates a test html site for it to be hosted in with some default settings, and uses VS2008 built-in hosting service, which does not allow communication to an address/port different from that of the hosting address. (even though Silverlight is a client side library, VS2008 can do this)
so if you want to run the Silverlight application natively, meaning actually executing the XAP, you can deploy it to IIS, and configure IIS to deliver XAP files, or just install it and run it out of browser and let it update from IIS the deployed version
Just copy a clientaccesspolicy.xml file (for an example take a look at this post; you can even use this sample) into the root of your webserver (eg: c:\inetpub\wwwroot\).
This should help.

Deploying a Silverlight Application with built-in ASMX WebService to IIS

I've got a Silverlight application which uses a built-in .ASMX WebService to access a SQL database and run some queries. Everything runs without any hitches on my Development machine.
I'm trying to deploy the application to IIS 6 and I'm having some issues.
The Silverlight application itself seems to run fine, however the Web Service does not. I get an unhandled exception error that says [Async_ExceptionOcurred] as soon as the page loads (when the page loads I'm making some Async WebService method calls).
I think this is an issue with the Web Service but I don't know what the problem is. I tried setting the WebService namespace to my URL, but that didn't work. I've tried messing with the SQL connection string in my Web Config but that also affects nothing.
One thing to note is that my IIS Virtual Directory only contains my SilverlightApp.Web folder. I know that the other folder that's part of the application contains a .ClientSettings file for the WebService, but I think this is embedded into the .xap.
Can anyone shed any light on this?
The most likely thing that's happening:
Your webservice proxy on the client is using the address of the web service it was built against: ("http://localhost...").
Things to do:
Use fiddler to confirm this is the issue. It will show you where the proxy is making the call to.
Use the overloaded constructor for the web service and specify a URI. Consider using id/deffing for debug/release. This will overwrite the settings in the client.config.
Create another endpoint in the client config for the release build (Shawn's article here) and select one or the other (again using if/defs).
There are other options as well (looking at the URI and building up the service adress)... but that's the general idea.
hth,
Erik

Resources