Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WebClient usage from Silverlight not working fo me (Security?)

WebClient usage from Silverlight not working fo me (Security?)

Scheduled Pinned Locked Moved WPF
helpcsharpasp-netwpfsecurity
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pisanis
    wrote on last edited by
    #1

    Hi, I have a strange problem I cannot seem to solve. I'm using, in Silverlight, and WebClient to invoke a REST service that returns an XML document. (the example below shows this document as being accessible via the url: "http://localhost/persons.xml" This is the callback code from a button defined in my XAML : Private Sub getdata_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim wcProxy As New WebClient() Dim Uri As New System.Uri("http://localhost/persons.xml") 'setup delegate AddHandler wcProxy.DownloadStringCompleted, AddressOf wcProxy_DownloadStringCompleted ' invoke service wcProxy.DownloadStringAsync(Uri) End Sub Private Sub wcProxy_DownloadStringCompleted(ByVal sender As Object, ByVal e As System.Net.DownloadStringCompletedEventArgs) Dim doc As New XDocument doc = XDocument.Parse(e.Result) <<< ERRORS HERE <<<< ... ... End Sub The error on the line marked above says: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. and: e.Error.InnerException.Message says: "Security Error" Not sure why this is. In at atempt to fix this, I have defined a file called 'clientaccesspolicy.xml' in my ASP.NET Web Application, with te following contents: However - I'm not 100% sure if I need this at all, and even if I did, if I implemented it correctly. I've made no other changes to the default .WEB project that the Silverlight 'New Project' creates for me. Thanks - S.

    M 1 Reply Last reply
    0
    • P pisanis

      Hi, I have a strange problem I cannot seem to solve. I'm using, in Silverlight, and WebClient to invoke a REST service that returns an XML document. (the example below shows this document as being accessible via the url: "http://localhost/persons.xml" This is the callback code from a button defined in my XAML : Private Sub getdata_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim wcProxy As New WebClient() Dim Uri As New System.Uri("http://localhost/persons.xml") 'setup delegate AddHandler wcProxy.DownloadStringCompleted, AddressOf wcProxy_DownloadStringCompleted ' invoke service wcProxy.DownloadStringAsync(Uri) End Sub Private Sub wcProxy_DownloadStringCompleted(ByVal sender As Object, ByVal e As System.Net.DownloadStringCompletedEventArgs) Dim doc As New XDocument doc = XDocument.Parse(e.Result) <<< ERRORS HERE <<<< ... ... End Sub The error on the line marked above says: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. and: e.Error.InnerException.Message says: "Security Error" Not sure why this is. In at atempt to fix this, I have defined a file called 'clientaccesspolicy.xml' in my ASP.NET Web Application, with te following contents: However - I'm not 100% sure if I need this at all, and even if I did, if I implemented it correctly. I've made no other changes to the default .WEB project that the Silverlight 'New Project' creates for me. Thanks - S.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You should probably make sure e.Error is Nothing before trying to use e.Result in your DownloadStringCompleted handler. Are you showing the entire error strings returned in the e.Error exceptions? If this is a cross-domain issue... Your clientaccesspolicy.xml needs to be published/copied to the root directory of the website at the domain you are accessing. What's in your clientaccesspolicy.xml file? Here's one that should allow any Silverlight cross domain service calls:

      <?xml version="1.0" encoding="utf-8"?>
      <access-policy>
      <cross-domain-access>
      <policy>
      <allow-from http-request-headers="*">
      <domain uri="http://*"/>
      <domain uri="https://*"/>
      </allow-from>
      <grant-to>
      <resource path="/" include-subpaths="true"/>
      </grant-to>
      </policy>
      </cross-domain-access>
      </access-policy>

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      P 1 Reply Last reply
      0
      • M Mark Salsbery

        You should probably make sure e.Error is Nothing before trying to use e.Result in your DownloadStringCompleted handler. Are you showing the entire error strings returned in the e.Error exceptions? If this is a cross-domain issue... Your clientaccesspolicy.xml needs to be published/copied to the root directory of the website at the domain you are accessing. What's in your clientaccesspolicy.xml file? Here's one that should allow any Silverlight cross domain service calls:

        <?xml version="1.0" encoding="utf-8"?>
        <access-policy>
        <cross-domain-access>
        <policy>
        <allow-from http-request-headers="*">
        <domain uri="http://*"/>
        <domain uri="https://*"/>
        </allow-from>
        <grant-to>
        <resource path="/" include-subpaths="true"/>
        </grant-to>
        </policy>
        </cross-domain-access>
        </access-policy>

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        P Offline
        P Offline
        pisanis
        wrote on last edited by
        #3

        Thanks. that was part of the problem.... I'm also using Apache not IIS, and couldn't succesfully locate the ROOT folder for the web app hosting the service. I switched to IIS, and, got it working which is enough for me for now. Thanks again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups