473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using WebClient to download string from ASP.NET Web Service Error

122 100+
I have a simple ASP.NET Web Service:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.Services;
  5. using System.Web.Script.Services;
  6. using System.Web.Script.Serialization;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI;
  9.  
  10. namespace WebService1
  11. {
  12.     /// <summary>
  13.     /// Summary description for Service1
  14.     /// </summary>
  15.     [WebService(Namespace = "http://tempuri.org/")]
  16.     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  17.     [System.ComponentModel.ToolboxItem(false)]
  18.     [ScriptService]
  19.     public class Service1 : System.Web.Services.WebService
  20.     {
  21.         [WebMethod]
  22.         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  23.         public string Get()
  24.         {
  25.             member mem = new member();
  26.             mem.hello = "hello hello hello";
  27.             mem.kalon = "fafasdf";
  28.             mem.name = "wfasdfawe";
  29.             return new JavaScriptSerializer().Serialize(mem);
  30.         }
  31.  
  32.         [WebMethod]
  33.         public string HelloWorld()
  34.         {
  35.             return "Hello World";
  36.         }
  37.     }
  38.  
  39.     public class member
  40.     {
  41.         public string hello { get; set; }
  42.         public string name { get; set; }
  43.         public string kalon { get; set; }
  44.     }
  45. }
  46.  
I'm facing problem to retrieve the string from SilverLight by using WebClient. Can you enlighten me? I uses the below code to get the string from the WebService.

Expand|Select|Wrap|Line Numbers
  1. WebClient wc = new WebClient();
  2.  
  3. public MainPage()
  4. {
  5.     InitializeComponent();
  6.     wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
  7. }
  8.  
  9. private void button1_Click(object sender, RoutedEventArgs e)
  10. {
  11.     Uri uri = new Uri("http://www.MyWeb.com/Service1.axms/Get");
  12.     wc.DownloadStringAsync(uri);
  13. }
  14.  
  15. void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  16. {
  17.     MessageBox.Show(e.Error.ToString());
  18.     MessageBox.Show(e.Result);
  19. }
  20.  
And I receive error:

System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalE ndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_Displ ayClass5.b_4(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.b _1(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPos tCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetRes ponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback( IAsyncResult result)

I have tried this too, still getting the same error:

Expand|Select|Wrap|Line Numbers
  1. Uri uri = new Uri("http://www.MyWeb.com/Service1.axms?op=Get");
  2. wc.DownloadStringAsync(uri);
Apr 30 '12 #1

✓ answered by adriancs


1 4424

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Sarbu | last post by:
I am downloading a file using WebClient.DownloadFile. The file is a dll, so I guess IIS thinks it's an ISAPI extension and it returns an HTTP 500 error. If I disable friendly error messages in IE I...
1
by: Rajesh S | last post by:
Hi, Is it possible to upload multiple files using WebClient Class(Like HttpRequest Class).? If Possible please help!!
0
by: Fabricio de Reuter Sperandio | last post by:
Hi everybody, I did an ASP.NET application to send a fax using the Extended Fax Service COM API. I am running Windows XP. The problem is: When I send Text files, it mens, the FaxDocument.Body...
5
by: Stu Carter | last post by:
Hi, ENV: Windows 2003 Server SP1 (+all updates), VS 2003, .Net 1.1 SP1 We've got an ASP.Net web application using State Service. All is fine until we tried to use the app through a virtual...
1
by: Kevin | last post by:
I need to send a request to a jsp with data added to the http request header. I am using Webclient to send the request and I am putting the returned string (html) into a label on my aspx page but...
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
3
by: tscamurra | last post by:
Hello, I have a web app that performs screen scaping and submits a form. My code worked until the page was changed to use .aspx code. I am updating my code to conform to the new pages but am...
2
by: AmitGujrathi | last post by:
can anybody pls help me? i m trying to upload file using webclient.Uploadfile() method. every thing happens fine. but if i open the uploaded file on server its format is changed. How to prevent...
2
by: Jeff | last post by:
ASP.NET 2.0 I'm working on a asp.net 2.0 website which needs to access a database on another server via an request. This database is placed on another server which is not based on ASP.NET, but...
3
by: =?Utf-8?B?SmVycnk=?= | last post by:
I am using Webclient.download to HTTP download a file from an IIS 6.0 server. It works for all the files I have except for those type .config. If I rename the files to .txt extension, it works....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.