tags:

views:

138

answers:

4

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

A: 

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.

Erik Mork
+1  A: 

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.

djjoyro
A: 

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

A: 

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%3A2753 is a dead giveaway that you still using the VS web server and not IIS as you intended.

wyldebill