views:

1032

answers:

3

I am trying to call a WCF webservice (which I developed) from a Silverlight application. For some reason the Silverlight app does not make the http soap call to the service. I know this because I am sniffing all http traffic with Fiddler (and it is not a localhost call).

This my configuration in the server relevant to WCF:

<system.serviceModel>
 <behaviors>
  <serviceBehaviors>
   <behavior name="ServiceBehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
   </behavior>
  </serviceBehaviors>
 </behaviors>
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
 <services>
  <service behaviorConfiguration="ServiceBehavior" name="Service">
   <endpoint address="" binding="basicHttpBinding" contract="Service"/>
   <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
 </services>
</system.serviceModel>

And the ServiceReferences.ClientConfig file in the silverlight app (i am using the beta 2):

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_Service" maxBufferSize="65536"
                maxReceivedMessageSize="65536">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://itlabws2003/Service.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_Service" contract="Silverlight_organigram.DataService.Service"
            name="BasicHttpBinding_Service" />
    </client>
</system.serviceModel>

This is the silverlight method that calls the service, I paste the whole method for copleteness, the lambda is to make the call synchronous, I have debugged it and after the line client.GetPersonsAsync(), Fiddler does not show any message travelling to the server.

    public static List<Person> GetPersonsFromDatabase()
    {
        List<Person> persons = new List<Person>();

        ServiceClient client = new ServiceClient();

        ManualResetEvent eventGetPersons = new ManualResetEvent(false);

        client.GetPersonsCompleted += new EventHandler<GetPersonsCompletedEventArgs>(delegate(object sender, GetPersonsCompletedEventArgs e)
            {
                foreach (DTOperson dtoPerson in e.Result)
                {
                    persons.Add(loadFromDto(dtoPerson));
                }
                eventGetPersons.Set();
            });

        client.GetPersonsAsync();
        eventGetPersons.WaitOne();

        return persons;
    }

Does anyone have any suggestions how I might fix this?

A: 

You wouldn't happen to be running from the filesystem would you? If you are serving up the silverlight application your local machine and not using the VS Web Server or IIS, you won't be able to make HTTP calls for security reasons. Similarly if you're loading from a web server, you can't access local resources.

Also I've found that Nikhil's Web Development Helper http://www.nikhilk.net/ASPNETDevHelperTool.aspx can be more useful than Fiddler because you will see local traffic as well, although it doesn't look like that is your issue in this case.

Bill Reiss
The website is running in IIS 6.1 on another machine in the local network
Dani Duran
A: 

I am not 100% certain, but if you are running on Vista or Server 2008 you may have run into the User Access Control issue with http.sys

So in Vista and Win2k8 server, the HttpListener will listen only if you are running under a high privelege account. In fact, from my experience, even if you add yourself to the local administrators group, you might run into this issue.

In any case, try launching Visual Studio on Vista by Right Clicking and runas Administrator. See if that fixes it. If it does, you're good, but....

ideally you should run httpcfg

like: httpcfg set urlacl -u http://itlabws2003 -a D:(A;;GX;;;yoursid)

your sid = the security identifier for the account you're running as, you can find it here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

if you don't know it already, or you could possibly add yourself to BUILTIN\Administators, find the sid and run the httpcfg via command line again, specifying that sid.

User Access Control, Vista and Http.sys cause all this...if this is indeed the problem you are running into. Not sure but maybe its worth a try

RandomNoob
also, this must be done on both boxes, if this indeed was the case.
RandomNoob
thanks for the response, I am running windows server 2003 and XP pro, so I guess that is not my case, buy however I will have that in mind.
Dani Duran
+1  A: 

If the Silverlight application is not hosted in the same domain that exposes the Web service you want to call, then cross-domain restrictions applies.

If you want the Silverlight application to be hosted in another domain than the web service, you may want to have a look on this post to help you to have a cross domain definition file, or to write a middle "proxy" instead.

controlbreak