Page view counter
webClient DownloadStringAsync failed Subscribe to this thread
Last post 10-26-2008 8:31 AM by pbromberg. 6 replies.
Sort Posts:
10-24-2008 2:34 AM
webClient DownloadStringAsync failed

Hi

I successfully send http request from winform C# application (see code1)
but from silverlight (see code2) I obtain an error.(see error)

Peharps the problem is that my server is https and the remote is also https.

How I modify my server to be http ???

Thanks in advance
Fred

code1 (Winform C# succeeded)

private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                WebClient client = new WebClient();
                // Add a user agent header in case the requested URI contains a query.
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                client.QueryString.Add("user", "AAA");
                client.QueryString.Add("password", "1111111");
                client.QueryString.Add("api_id", "3126312");
                client.QueryString.Add("to", "972545665417");
                client.QueryString.Add("text", "This is an example message");
                string baseurl = "http://api.clickatell.com/http/sendmsg";
                Stream data = client.OpenRead(baseurl);
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
                data.Close();
                reader.Close();
                MessageBox.Show(s);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

code2 (silverlight failed)

private void sendSMS()
        {
            WebClient client = new WebClient ();
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
           
            string baseurl ="http://api.clickatell.com/http/sendmsg";
            baseurl +="?user=AAA";
            baseurl +="&password=1111111";
            baseurl +="&api_id=3126312";
            baseurl +="&to=972545665417";
            baseurl +="&text=This+is+an+example+message";

            Uri uri = new Uri(baseurl, UriKind.Absolute);
            client.DownloadStringAsync(new Uri(baseurl));
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
           
            if (e.Error == null)
            {
                string s = e.Result.ToString();
                Debugger.Log(0, "debug", "s=" + s+ "\r\n");
            }
            else
                Debugger.Log(0, "debug", "error=" + e.Error.ToString()+ "\r\n");
        }

error
baseurl=http://api.clickatell.com/http/sendmsg?user=AAA&password=1111111&api_id=3126312&to=972545665417&text=This+is+an+example+message
'iexplore.exe' (Silverlight): Loaded 'C:\Program Files\Microsoft Silverlight\2.0.31005.0\en-US\mscorlib.debug.resources.dll'

error=System.Security.SecurityException ---> System.Security.SecurityException: Security error.
   at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
   at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)

work2gs

Loading...
Joined on 05-26-2008
Posts 75
10-25-2008 2:57 AM
Re: webClient DownloadStringAsync failed

Have you created a crossdomain file on your server? The error you're getting looks like a crossdomain security issue.

(If this has answered your question, please click on mark as answer on this post)

Cheers!
Rob Houweling



My blog

robhouweling

Loading...
Joined on 03-01-2008
Ede (the Netherlands)
Posts 506
10-25-2008 2:15 PM
Re: webClient DownloadStringAsync failed

 Thanks for your response

I define a clientaccesspolicy.xml in my web application that contains this 

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

without success

Could you tell me what is missing ?

thanks

Fred 

work2gs

Loading...
Joined on 05-26-2008
Posts 75
10-26-2008 3:56 AM
Re: Re: webClient DownloadStringAsync failed

 try to install fiddler to check if someone is wrong ;)...have a look to my old post: http://silverlight.net/forums/t/39985.aspx

 

Evs_

Loading...
Joined on 10-19-2008
Italy
Posts 71
10-26-2008 5:12 AM
Re: Re: webClient DownloadStringAsync failed

Hi

Do you mean that the remote server (api.clickatell.com)

I try to access have to be the clientaccesspolicy.xml existing ?

This is what I obtain from Fiddler

 GET http://api.clickatell.com/clientaccesspolicy.xml
404 Not Found

 .REQUEST { font: 8pt Courier New; color: blue;} .RESPONSE { font: 8pt Courier New; color: green;}GET /clientaccesspolicy.xml HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: api.clickatell.com
Proxy-Connection: Keep-Alive

HTTP/1.1 404 Not Found
Via: 1.1 Address Is Hidden
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Content-Length: 304
Date: Sun, 26 Oct 2008 08:57:58 GMT
Content-Type: text/html; charset=iso-8859-1
Server: Apache/2.2.3 (Red Hat)
Keep-Alive: timeout=10, max=50

 

Thanks

Fred

work2gs

Loading...
Joined on 05-26-2008
Posts 75
10-26-2008 5:28 AM
Re: Re: Re: webClient DownloadStringAsync failed

 HI, as you can see, clientpolicy.xml  must be on the server( your application tries to download it but it can't find)....

So you have to put it on the server, not in your application ;)

Mark this post  as answer if it solves your problem ;)

Bye 

Evs_

Loading...
Joined on 10-19-2008
Italy
Posts 71
10-26-2008 8:31 AM
Marked as Answer
Re: webClient DownloadStringAsync failed

Have a look at their crossdomain.xml policy file and you'll see why Siliverlight will not let you do this:

 

http://api.clickatell.com/crossdomain.xml

 

What you need to do is create your own service on the same server that your Silverlight App is served from, and have that service make the call.

[C# MVP]
Unblog|WebSite|IttyUrl

pbromberg

Loading...
Joined on 06-25-2002
Orlando FL
Posts 282
Microsoft Communities