Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Web Service
1 replies. Latest Post by Jim Mangaly on May 10, 2008.
(0)
Djangoo
Member
34 points
34 Posts
05-10-2008 2:42 PM |
How to access the Web service Class after, I have in my SL 2.0 project, added references to Web services?
This is the Page.xaml.cs:
using SilverlightApplication4.ServiceReference1;namespace SilverlightApplication4{ public partial class Page : UserControl { public Page () { InitializeComponent (); } private void Button_MouseLeftButtonDown ( object sender, MouseButtonEventArgs e ) { /* If this was aspx page I would do only this:
WebService ws = new WebService();
ws.HelloWorld ( "some args" ); } }}
This is the WebService.cs:
/// <summary>/// Summary description for WebService/// </summary>[WebService ( Namespace = "http://tempuri.org/" )][WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )]// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService]public class WebService : System.Web.Services.WebService{ public WebService () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string HelloWorld ( string x) { return x; }}
Jim Mangaly
Contributor
2610 points
380 Posts
05-10-2008 2:52 PM |
Take a look at this post by Tim Heur. It has explanation + sample for accessing data via WCF, asmx and REST. Look at the asmx example since that is your scenario.
All service calls in Silverlight are asynchronous calls. So you will see in that sample that the asmx service call is "wrapped" by WCF-related API's as shown below:
{
BasicHttpBinding bind =
AsmxService.SimpleAsmxSoapClient asmx =
asmx.HelloWorldWithAsmxAsync(StringToEmit.Text);
}
OutputString.Text =
I would recommend that you check out the whole sample.
Hope this helps,Jim (http://jimmangaly.blogspot.com/)
Please MARK the replies as answers if they answered your question