I have a simple ASP.NET Web Service:
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.
And I receive error:
System.Security .SecurityExcept ion ---> System.Security .SecurityExcept ion: Security error. at System.Net.Brow ser.BrowserHttp WebRequest.Inte rnalEndGetRespo nse(IAsyncResul t asyncResult) at System.Net.Brow ser.BrowserHttp WebRequest.<>c_ DisplayClass5.b _4(Object sendState) at System.Net.Brow ser.AsyncHelper .<>c_DisplayCla ss4.b_1(Object sendState) --- End of inner exception stack trace --- at System.Net.Brow ser.AsyncHelper .BeginOnUI(Send OrPostCallback beginMethod, Object state) at System.Net.Brow ser.BrowserHttp WebRequest.EndG etResponse(IAsy ncResult asyncResult) at System.Net.WebC lient.GetWebRes ponse(WebReques t request, IAsyncResult result) at System.Net.WebC lient.DownloadB itsResponseCall back(IAsyncResu lt result)
I have tried this too, still getting the same error:
Code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Get()
{
member mem = new member();
mem.hello = "hello hello hello";
mem.kalon = "fafasdf";
mem.name = "wfasdfawe";
return new JavaScriptSerializer().Serialize(mem);
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
public class member
{
public string hello { get; set; }
public string name { get; set; }
public string kalon { get; set; }
}
}
Code:
WebClient wc = new WebClient();
public MainPage()
{
InitializeComponent();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("http://www.MyWeb.com/Service1.axms/Get");
wc.DownloadStringAsync(uri);
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Error.ToString());
MessageBox.Show(e.Result);
}
System.Security .SecurityExcept ion ---> System.Security .SecurityExcept ion: Security error. at System.Net.Brow ser.BrowserHttp WebRequest.Inte rnalEndGetRespo nse(IAsyncResul t asyncResult) at System.Net.Brow ser.BrowserHttp WebRequest.<>c_ DisplayClass5.b _4(Object sendState) at System.Net.Brow ser.AsyncHelper .<>c_DisplayCla ss4.b_1(Object sendState) --- End of inner exception stack trace --- at System.Net.Brow ser.AsyncHelper .BeginOnUI(Send OrPostCallback beginMethod, Object state) at System.Net.Brow ser.BrowserHttp WebRequest.EndG etResponse(IAsy ncResult asyncResult) at System.Net.WebC lient.GetWebRes ponse(WebReques t request, IAsyncResult result) at System.Net.WebC lient.DownloadB itsResponseCall back(IAsyncResu lt result)
I have tried this too, still getting the same error:
Code:
Uri uri = new Uri("http://www.MyWeb.com/Service1.axms?op=Get");
wc.DownloadStringAsync(uri);
Comment