• Calling web services with Silverlight 2


    UPDATE: Source code posted here.

    Now that Silverlight 2 is out to the masses (even in beta form), there are likely a lot of developers looking to wire-up web services with their applications in .NET rather than the Silverlight 1.0 method of Javascript.  I thought I'd give you some quick examples of how to do this using some different methods: ASP.NET Web Services (ASMX), Windows Communication Foundation (WCF), REST service, and talk about cross-domain calls.  These are meant to be examples using very much 'hello world' style services, but demonstrating at least how to execute the call.

    If you are an ASP.NET developer, you likely are familiar with ASMX web services and the fact that they generate WSDL for anyone looking at their endpoint.  Basically you write some code, host it some where and anyone can call it.  Most of the time, the caller will be using SOAP to connect unless you also enabled other methods on that service.  When consuming the ASMX service you probably used Add Web Reference in Visual Studio and then did something like this:

    SimpleWebServiceSoapClient svc = new SimpleWebServiceSoapClient();
    string returnValue = svc.HelloWorld();

    Fine and simple.  A few lines of code and you are calling your service getting it back value data.  This is a synchronous call.  Of course there are ways to make async calls with ASMX services, but my point is that most typical implementations of ASMX services aren't like that from what I've seen in casual use.  This is where Silverlight may differ for these developers.  In Silverlight 2, all service calls are asynchronous.  Let's take a look at how this is accomplished.

    I'm going to use the same application throughout this sample.  The user interface is quite lame, but that's not what this is about.  I'm using a TextBox, TextBlock, and three Buttons all in a StackPanel layout.  =Hhere's what it looks like:

    That represents the Silverlight application.  In the web project hosting the Silverlight app, I have 2 services: "SimpleAsmx" and "WcfService" -- aptly named so that they clearly represent the implementing technology.  They are both simple services that expose a method that takes a single string param and basically outputs it back out.  Again, the service portion is not what I'm concentrating on here -- I'm looking at the calling of the service.

    Now that we have our layout and our web services, let's start tying them together.  My project looks like this for reference:

    ASMX Web Service

    In our Silverlight application, I'm going to choose to 'Add Service Reference' from Visual Studio.  This is the same method of previous 'Add Web Reference' but renamed essentially.  When I do that I click Discover and it finds my ASMX service which I select (and rename to AsmxService):

    Once I have done that, Visual Studio has wired up a proxy object for me to use in my code.  In my Silverlight application I wire up the Click event in my ASMX Button to an event handler and start writing code.  The first thing you will notice is that implementing the service isn't the same as previously like noted above.  Using ASMX services in Silverlight still uses SOAP, but it also uses the same model of calling a WCF service, which means you have to define a binding and endpoint.  For our ASMX service our binding will be a BasicHttpBinding and our endpoint is our URI to the .asmx file):

    UPDATE 19-MAR: The code below will absolutely work (specifying the binding and endpoint information).  However, you can also choose not to specify the binding/endpoint and it should still work.  For the WCF service code below, if you don't change the wsHttpBinding to basicHttpBinding BEFORE you make the service reference in your Silverlight application, then you will have to update your service reference in your Silverlight app (simply right-click on the service and choose 'update service reference').  Doing this will generate the correct proxy code for basicHttpBinding and enable you to just call the code using proxy.YourService() as a constructor rather than using a binding and endpoint.

    BasicHttpBinding bind = new BasicHttpBinding();
    EndpointAddress endpoint = new EndpointAddress(http://localhost/SimpleAsmx.asmx);

    Now that we have those lines, we can new up our service, noticing that the constructor accepts a binding/endpoint for us, so we pass those in:

    SimpleAsmxSoapClient asmx = new SimpleAsmxSoapClient(bind, endpoint);

    The next step is to call our service.  Remember, we are doing things asynchronously.  So first, we wire up the async handler for when the service is called:

    asmx.HelloWorldWithAsmxCompleted += 
       new EventHandler<HelloWorldWithAsmxCompletedEventArgs>(asmx_HelloWorldWithAsmxCompleted);

    After that we can now call the service.  The resulting full code looks something like this:

    private void AsmxServiceButton_Click(object sender, RoutedEventArgs e)
    {
        BasicHttpBinding bind = new BasicHttpBinding();
        EndpointAddress endpoint = new EndpointAddress("http://localhost/SimpleAsmx.asmx");
    
        SimpleAsmxSoapClient asmx = new SimpleAsmxSoapClient(bind, endpoint);
        asmx.HelloWorldWithAsmxCompleted += 
           new EventHandler<HelloWorldWithAsmxCompletedEventArgs>(asmx_HelloWorldWithAsmxCompleted);
        asmx.HelloWorldWithAsmxAsync(StringToEmit.Text);
    }

    The event handler for our Completed event looks like this:

    void asmx_HelloWorldWithAsmxCompleted(object sender, HelloWorldWithAsmxCompletedEventArgs e)
    {
        OutputString.Text = string.Format("Output from ASMX: {0}", e.Result.ToString());
    }

    Basically when the event completes, the arguments provide us a Result object that represents the return type, in this case a String.  I can then put that string in my TextBlock as output.  And there you have it...we've called a simple ASMX web service.

    WCF Services

    Calling a WCF service isn't much different (in fact any different).  There is a couple config differences that you have to be aware of which I'll point out here.  But since ASMX services in Silverlight are implemented using the WCF constructs.  Here's the full implemented service with event handler using the same concept:

    private void WcfServiceButton_Click(object sender, RoutedEventArgs e)
    {
        BasicHttpBinding bind = new BasicHttpBinding();
        EndpointAddress endpoint = new EndpointAddress("http://localhost/WcfService.svc");
    
        WcfServiceClient wcf = new WcfServiceClient(bind, endpoint);
        wcf.HelloWorldFromWcfCompleted += 
          new EventHandler<HelloWorldFromWcfCompletedEventArgs>(wcf_HelloWorldFromWcfCompleted);
        try
        {
            wcf.HelloWorldFromWcfAsync(StringToEmit.Text);
        }
        catch (Exception ex)
        {
            OutputString.Text = ex.Message;
        }
    }
    
    void wcf_HelloWorldFromWcfCompleted(object sender, HelloWorldFromWcfCompletedEventArgs e)
    {
        try
        {
            OutputString.Text = string.Format("Output from WCF: {0}", e.Result.ToString());
        }
        catch (Exception ex)
        {
            OutputString.Text = ex.Message;
        }
    }

    I mentioned a config change that you have to do.  When you add a WCF service to an ASP.NET application, it alters the web.config to add some binding information.  By default it adds an endpoint configuration but adds it like this:

    <endpoint address="" binding="wsHttpBinding" contract="IWcfService">

    Silverlight communicates using the BasicHttpBinding for WCF, so you have to change it to this (or add another endpoint with this binding):

    <endpoint address="" binding="basicHttpBinding" contract="IWcfService">

    And then you are done and the code should work.

    REST S

    Now let's talk about REST.  What is REST?  Representational State Transformation...read about it here.  REST basically takes advantage of existing HTTP verbs (GET, PUT, POST, DELETE) and enables access to actions based on those.  Because of this there is no real "contract" as you may be expecting, or WSDL definitions.  You execute a verb and you'll get a response, usually in XML.  Because there is not contract essentially, the 'Add Service Reference' won't work well for you.  Instead in Silverlight you'll want to use WebClient or HttpWebRequest.  What's the difference?  Here's the timheuer version.  WebClient is a simpler implementation doing GET requests really easily and get a response stream.  HttpWebRequest is great for when you need a bit more granular control over the request, need to send headers or other customizations.  For my sample here, I'm using WebClient because that is all I need.

    First a note on remote web services, aka cross-domain services.  In Silverlight 1.0 you couldn't directly access cross-domain services.  In Silverlight 2, we are enabling support for doing that.  The approach we've taken so far is one where we have put the control of the access to the service to the owner of the service.  What that means is that you can't call *any* service on the web, but rather ones that have enabled permission to sites (or everyone) to call their services via rich internet applications.  Flash has enabled the same procedure for a while.  They use a policy access file called crossdomain.xml.  You can read more about this format at crossdomainxml.org.  Silverlight 2 currently supports the exact same policy file.  In addition, Silverlight has a policy file format, but in the end, both are supported, which is cool.  So if you have a web service on a domain separate from your Silverlight application, you'll have to create the policy file at the endpoint root of your web service to enable rich internet platforms to support it.

    Once that policy file is in place you are good to go.  For demonstrating REST I am choosing to show you one that is a public API and has a policy file...Flickr.  My sample basically calls Flickr's REST API to search for photos based on a tag and then the result is to add Image elements to my Silverlight DOM in a StackPanel.  Here's what it looks like (after the wire-up button is hooked up).  In my click event handler it looks like this:

    WebClient rest = new WebClient();
    rest.DownloadStringCompleted += new DownloadStringCompletedEventHandler(rest_DownloadStringCompleted);
     rest.DownloadStringAsync(new Uri(flickrApi));

    The "flickrApi" variable represents the REST api call to search photos for Flickr.

    The async callback basically gets the Flickr REST response (XML) and parses it using LINQ, then adding a new Image element to the Silverlight tree:

    string data = e.Result;
    string url = string.Empty;
    
    FlickrImages.Children.Clear();
    
    XDocument doc = XDocument.Parse(e.Result);
    var photos = from results in doc.Descendants("photo")
                select new
                {
                    id = results.Attribute("id").Value.ToString(),
                    farm = results.Attribute("farm").Value.ToString(),
                    server = results.Attribute("server").Value.ToString(),
                    secret = results.Attribute("secret").Value.ToString()
                };
    
    foreach (var photo in photos)
    {
        url = string.Format("http://farm{0}.static.flickr.com/{1}/{2}_{3}_m.jpg", 
          photo.farm, photo.server, photo.id, photo.secret);
        Image img = new Image();
        img.Stretch = Stretch.Fill;
        img.Margin = new Thickness(10);
        img.Source = new BitmapImage(new Uri(url));
        FlickrImages.Children.Add(img);
    }

    The result of which is 5 pictures added to my Silverlight application, and looks horrible like this:

    So that's it, web services (hopefully) made simple.  I hope this helps.  What did I miss?

    Friday, March 14, 2008 6:37 PM

    PostTypeIcon

Comments.

  • Gravatar
    # re: Calling web services with Silverlight 2


    Tim,

    Thanks much, nice example; we'll try the ASMX & REST options, as the WCF seems to suffer some latency compared to our 1.1 implementation. Have you considered writing, or do you know of a 2-way HttpWebRequest example for AG2?

    3/14/2008 7:47 PM
  • Ash said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi,

    Thanks for the post. I am new to webservices and am trying to tie together the various sources of info that I have found. I have watched the excellent mix08 presentationd one by Eugene Osovetsky which does not seem to have this code:

    BasicHttpBinding bind = new BasicHttpBinding();
    EndpointAddress endpoint = new EndpointAddress("http://localhost/WcfService.svc");

    Can you please clarify why this is needed.

    Thanks.

    3/16/2008 2:39 AM
  • Gravatar
    # duplex binding


    Can i use duplex binding with wcf services?

    3/16/2008 6:32 AM
  • Kev Moore said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi,

    Has anyone experience a "Async_ExceptionOccurred" exception? I have checked my WCF Service through IE and all is well, as well as having several unit tests performing Async calls. They all work fine. I have also added a crossdomain.xml just in case, but just cannot get the silverlight control to bind to the WCF Service.

    Any help would be appreciated.

    Kev Moore

    3/16/2008 11:42 AM
  • Neeta said:
    Gravatar
    # re: Calling web services with Silverlight 2


    First,Let me thank you for a nice and simplified post.
    I tried your approach.However I am getting "Syste.ServiceModel.ProtocolException in System.ServiceModel.dll".
    Do you know why is this exception coming?
    Thanks in advance

    3/16/2008 3:35 PM
  • Amit said:
    Gravatar
    # re: Calling web services with Silverlight 2


    I'm also facing the same problem as Neeta.

    3/17/2008 9:58 PM
  • Yousaf said:
    Gravatar
    # re: Calling web services with Silverlight 2


    I have an asmx webservice in which every method returns a Soap 1.1 response that consists of an XMLNODE and some other strings . How can i use it with silverlight. or Do i have to create a WCF service, and how to handle the case that the methods in my webservice returns custom Objects like Books, Customers, Dealers.

    3/18/2008 12:34 AM
  • Andrew said:
    Gravatar
    # re: Calling web services with Silverlight 2


    >I'm also facing the same problem as Neeta.

    I had this problem with self hosted service. After move service to the same web site problem disapeared O_o

    3/18/2008 4:47 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Yousef: you can use your asmx web service the same (see the first part of this post)

    andrew: the problem was cross app-domain. you could keep your service in the original location as long as you added a crossdomain.xml policy file enabling support.

    3/18/2008 8:15 AM
  • Thomas said:
    Gravatar
    # re: Calling web services with Silverlight 2


    This was real help. Thanks.
    But I am stuck at the end. Below is the error I am facing and cannot get around. Please some one help.I did everything as the article says.
    "
    e.Result however returns the following;

    'e.Result' threw an exception of type 'System.Reflection.TargetInvocationException'

    base {System.Exception}: {System.Reflection.TargetInvocationException: [Async_ExceptionOccurred]

    Arguments:

    Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See go.microsoft.com/fwlink ---> System.Exception:
    "

    3/18/2008 9:29 AM
  • Tolga said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Thanks...good post!

    3/18/2008 2:28 PM
  • JTost said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi!

    I'm new on Silverlight 2.0 and I'm trying to implement a client application for a SOAP web service.

    First of all, I've added the service reference ("Add service reference...") from the web service's WSDL. From here on, when I send something to server, for example the known command "hello", that returns 'hello' when it is called, and is like a ping command:

    BasicHttpBinding bind = new BasicHttpBinding();
    EndpointAddress endpoint = new EndpointAddress("http://localhost:8080");

    tssSoapNS.tssSoapPortTypeClient service = new tssSoapNS.tssSoapPortTypeClient(bind,endpoint);
    try
    {
    strOutput.Text = service.hello("hello");
    }
    catch (Exception ex)
    {
    strOutput.Text = "Hello Response error: " + ex.Message;
    }



    It returns "Hello Response error: Method 'q1:hello' not implemented: method name or namespace not recognized". It seems that the client app adds a "q1" namespace that doesn't exists. Someone know why it happens? I have some other applications based on the same WSDL and it runs.

    Thanks for your help!!!



    Jordi

    3/19/2008 2:22 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    JTost: look at the section above for calling web services. I also added the sample project to this post so you can see. You have to call the service asynchronously.

    3/19/2008 6:40 AM
  • Steve O. said:
    Gravatar
    # re: Calling web services with Silverlight 2


    This is all great, but I have hundreds of web services developed with thousands of methods that return DataSets! How am I supposed to use these with Silverlight? There should be some sort of lightweight DataSet support in Silverlight so I can wire up my existing Web Services now!

    3/20/2008 3:33 PM
  • Sergey said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi Tim,

    Did you try to host this sample at IIS and open it over browser?

    I've tried and got exception:

    [Async_ExceptionOccurred]
    Arguments:
    Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=2.0.30226.2&File=System.dll&Key=Async_ExceptionOccurred

    Can you help me?

    3/21/2008 11:12 AM
  • Gravatar
    # re: Calling web services with Silverlight 2


    Do you believe that if I get e.result = "" it is because there's no crossdomain.xml in the service provider? I am trying to read a playlist feed from youtube, and in this case it only fails from within Silverlight. It works from a normal aspnet webpage.

    3/22/2008 1:03 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    hooligannes: youtube only allows cross domain access from their properties (you can look at the crossdomain.xml file for details)

    3/22/2008 1:36 PM
  • Jon Heupel said:
    Gravatar
    # re: Calling web services with Silverlight 2


    One thing to note is if you register your completed event handler in your button click method you will add a new completed event handler each time you push the button.

    The first time you push it asmx_HelloWorldWithAsmxCompleted will be executed once. The second time asmx_HelloWorldWithAsmxCompleted will be executed 2 times and the third press three times etc...

    It's fresh in my head because I spent a couple hours learning that the hard way :)

    3/24/2008 2:15 PM
  • Ras said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Thank you for a nice post.

    We have a lot of code like this (very large app):

    object Method1{
    int result = CallServiceA();

    if(result > 42){
    return CallServiceB()
    }
    else{
    return CallServiceC()
    }
    }

    object Method2{
    int result = CallServiceA();

    if(result < 120){
    return CallServiceD(parm1, parm2, parm3)
    }
    else {
    string value = CallServiceE()

    if (value.Length > 0) {
    return CallServiceC(parm1)
    }
    else{
    return CallServiceX(parm1, parm2)
    }
    }
    }

    I really don't see how we can implement this using asynchronous service calls without having to code hundreds of lines of goto-like spaghetti code.

    Any suggestions on how to go about something like this other than moving all logic to the server (which kind of defeats the purpose of SL)?

    Thanks!

    3/25/2008 10:41 AM
  • Jace said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hey Tim,

    Thank you, thank you and thank you – from good old blighty (UK)

    Excellent blog and made everything so simple…

    Just a couple of points I noticed which may help others (forgive me if this is obvious):-

    I got it working without specifying the bind and endpoints (as you suggested in your recent update). But couldn’t for the life of me get it to work when following your code sample… perhaps I was being a bit slow, but noticed I wasn’t the only one so thought I’d mention that I did finally get it working, but only providing I specified the correct port and fully qualified path to the asmx file.

    In your case it looks like it should have been:-

    http://localhost:50042/CallingServices_Web/Services/SimpleASMX.asmx

    and not:-

    http://localhost/SimpleAsmx.asmx as suggested in your code.

    Many thanks (again)

    J

    3/26/2008 8:49 AM
  • Joel said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Great post on SL2. I've been trying to get your sample app to work, but it always throws the CommunicationException [CrossDomainError].

    Any idea how to remedy this?

    Some articles suggest using a static port for the web project, but this doesn't make any difference for me. Do you just test in IIS or will the sample project work in the debug environment?

    Thanks!

    3/26/2008 1:20 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Joel: i attached the sample code i used (in full) to the top of this post. take a look there and see if it helps. you may have x-domain issues if your setup is different. if you are calling a service on another app domain, that service has to host a polic file to enable x-domain access. the sample project, however should work in the built-in web server in VS as that is what i used...double check all the ports, etc.

    one thing to note is the code in my blog post is slightly different (i removed port numbers, etc. to make it readable)

    3/26/2008 1:24 PM
  • Joel said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Thanks for the quick response Tim!

    I'm trying to run the sample code that you provide without modification. (XP/VS2008/SL2B1/Firefox)

    When I try to debug, Visual Studio gives me this warning:
    http://www.tundrasoftware.net/temp/Silverlight_Service_Warning.png

    And then when I actually invoke the services, this error occurs:
    http://www.tundrasoftware.net/temp/Silverlight_CrossDomainError.png

    Part of the problem seems to be that Visual Studio brings up my Silverlight test page through the filesystem, rather than the web server in the browser. If I make the browser use http://localhost:50042/CallingServices_Web/CallingServicesTestPage.html , everything works.

    But I added both the flash (crossdomain.xml) and silverlight (clientaccesspolicy.xml) cross domain access policy files to my website and the filesystem-based Silverlight page still threw the error. Is this just a funky situation or am I implementing cross domain service access incorrectly?

    Thanks again!
    Joel

    3/26/2008 1:56 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    joel: ah yes, you are experiencing cross-protocol issues. silverlight does not allow access across protocols. i.e., browing via file system, but accessing HTTP service is not allowed. glad you got it working!

    3/26/2008 2:08 PM
  • Mike said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Good post to get us started, but I'd like to second Steve O's question:

    What happened to datasets? (...did it go the way of the dodo in Silverlight?)

    Also, everyone is showing us how to PULL data. My Kingdom for examples that show us how to PUSH (save) changed data back to the server using WCF.

    I know Silverlight is new and everyone is just trying to figure it out, but this is pretty fundamental stuff. I'm surprised at how little information there is out there on persisting changed data to a remote server (ie. doing it the Silverlight way).

    3/26/2008 5:11 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Mike: whenever i hear datasets in web services i wonder what data is in there. most of the time i've seen datasets for use of one table -- too much unnecessary overhead in my opinion.

    you can still push data to a WCF service how you would. If you are talking about bulk updating then you'd want to design your architecture accordingly.

    right now, Silverlight doesn't have ADO.NET in it, so there is no DataSet, but there is LINQ and soon likely a hook to the entity data framework -- so that might be the option you are looking for. these are all good observations and just a reminder we are in beta 1, so there might be more forthcoming. i'm not saying i've got a crystal ball, i could be dead wrong, but just speculating.

    but my rule of thumb has been that every technology platform doesn't always translate. if you built your services layer based on datasets, then a java client really isn't ready to consume them either, so how 'soa-friendly' is it really. not knocking anyone's implementation, but just observations over the past years of seeing datasets used only to see: DataSet.Tables[0].Rows[0][0] to get scalar information out of it ;-)

    3/26/2008 6:39 PM
  • geordie said:
    Gravatar
    # re: Calling web services with Silverlight 2


    great one!
    iyho, which of the three is the best today, and prepares best for the future

    thanks

    3/27/2008 12:09 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    geordie: if you are developing services and on .net, i would say WCF will give you the best options as you can expose it using various different endpoints for flexibility.

    3/27/2008 12:48 PM
  • vitya said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi Tim, good article, well done. It helped me understand the fundamentals.
    I still have one problem left: It works OK on localhost, but when I deploy it to the production server, it gives me the following error:

    An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

    Additional information: [UnexpectedHttpResponseCode]
    Arguments:Not Found

    The test code I am using is very simple, empty functions everywhere, still, it fails every time on the published build, but works flawlessly on localhost. I added both x-domain policy files. What else am I missing?

    Thanks in advance!

    vitya

    3/29/2008 2:02 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    vitya: are you browsing over http and the service is hosted over http? ProtocolException usually means a cross protocol error (meaning an http hosted silverlight object cannot access https based resources for example)

    3/29/2008 7:09 AM
  • ptoinson said:
    Gravatar
    # re: Calling web services with Silverlight 2


    I have a very simple test app which includes a WCF service http://localhost/Service.svc), a Web site, and a Silverlight project. The silverlight page contains one TextBlock that displays the integer returned from the WCF service call and is embedded in the 1 web page in the web app. I run the web app and it works great (http://localhost/) yayyy. I run the web app using https://localhost/ and I get an exception (below). When using https://localhost/ to show the page I also use https://locahost/Service.svc for the service EndPoint.

    Sys.InvalidOperationException: ManagedRuntimeError error #4002 in control 'Xaml1': System.ArgumentException: via Parameter name: [InvalidUriScheme] Arguments:https,http Debugging resource strings are unavailable.

    4/2/2008 2:01 PM
  • Atmos said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Very nice!

    Since Silverlight version 2 doesn't use Javascript for Soap calls anymore, how am I going to share websessions between my ASPX pages and corresponding webservices ?

    4/3/2008 6:24 AM
  • yaip said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Tim,

    I too am getting the same error as Vitya - An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

    But this is happening to me on my DEV box. And I am not running anything on HTTPS

    4/8/2008 3:03 PM
  • Spin said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Tim, I get an ASYNC_ExceptionOccured when trying to debug your example. I tried debugging your example because my adaption of it on to my iis site gave the same error. That is when I click the WCF button or when I run the debugger. So I decided to just see what your program looked like in the debugger and got the same error. But your example works fine running the test page in the browser. Any suggestions?

    Spin

    4/9/2008 1:00 PM
  • chadbr said:
    Gravatar
    # re: Calling web services with Silverlight 2


    1) Thanks for the solution Tim -- very helpful.

    2) For all the $@%!@$%$#%'s like me that spend 2 hours trying to figure out how to get this to run:

    -Unzip the solution
    -Open in VS
    -Right click on the website and select "Set as Startup Project"
    -Right click on CallingServicesTestPage.aspx and select "Set as Start Page"

    Run the debugger and it all works fine...

    chadbr

    4/22/2008 1:17 PM
  • lakki said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hi,
    This solution is really helpfull.
    I have a silverlight Application, and a webservice in the same domain, which further talks to an another webservice.

    but after doing all these i am getting the below exception.



    An exception of type 'System.ServiceModel.ProtocolException' occurred in System.ServiceModel.dll but was not handled in user code

    Additional information: The remote server returned an unexpected response: (404) Not Found.

    could anyone please help me..

    4/22/2008 11:36 PM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    @lakki: can you do a trace and see *what* request is returning a 404?

    4/23/2008 1:22 AM
  • lakki said:
    Gravatar
    # re: Calling web services with Silverlight 2


    hey thanks for the reply! I got the output!
    i dint change any part of the code(except for the endpoint address),it suddently started working like a charm!

    4/23/2008 2:48 AM
  • chadbr said:
    Gravatar
    # re: Calling web services with Silverlight 2


    OK - now that I've changed the debugging settings as above, I can't debug my Silverlight code.

    No breakpoints are picked up, etc.

    Can anyone enlighten me on what I need to set to debug the client and server side at the same time?

    Thanks

    4/23/2008 9:54 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    @chadbr: right click on the web site project and view property pages...go to the build area and set the checkboxes as desired.

    4/24/2008 6:06 AM
  • chadbr said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Tim - you're a peach -- thanks.

    FWIW -- the settings are on the "Start Options" tab --

    4/24/2008 9:35 AM
  • Ordwin said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Last week I started using Silverlight 2 to develop a rich internet application. I want to connect this app to our existing software using the existing asmx web service. The above information allowed me to establish a connection successfully when invoking a web service that returns plain text. However the data that is returned by the existing web services contains sensitive information. To protect this data we encrypt each soap message using a customized soap extension. Is it possible to decrypt these message inside the silverlight application? I am currently looking into that issue as we speak but haven't found a solution yet.
    (e.g. I can not add a reference to System.Web.Services.Protocols inside the silverlight application)

    4/28/2008 4:11 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    @ordwin: if you are using custom soap extensions that might not work. Silverlight currently only supports the basic profiles for web services, so advanced techniques on existing services might not work. additionally, the same decryption technique would have to exist on your client (silverlight) and depending on what you are doing, you might not have the matching cryptography libraries.

    4/28/2008 8:15 AM
  • Ordwin said:
    Gravatar
    # re: Calling web services with Silverlight 2


    Hello Tim,

    I discovered that Silverlight does support some cryptography libraries, including the one we use. However we use it inside a class that inherits from System.Web.Services.Protocols.SoapExtension. Do you know if silverlight is supporting this or what I need to do to use something similar like this when adding the asmx service as service reference:

    Public Overrides Sub ProcessMessage(ByVal message As System.Web.Services.Protocols.SoapMessage)
    Select Case message.Stage
    Case SoapMessageStage.BeforeSerialize
    'body
    Case SoapMessageStage.AfterSerialize
    'body
    Case SoapMessageStage.BeforeDeserialize
    'body
    Case SoapMessageStage.AfterDeserialize
    'body
    End Select
    End Sub

    4/28/2008 10:36 AM
  • timheuer said:
    Gravatar
    # re: Calling web services with Silverlight 2


    @ordwin: we don't support SoapExtension, but do support the newer ServiceModel.Channel stack.

    5/1/2008 12:21 PM

Your Reply.

  Comment Form  

Fields denoted with a "*" are required.

*Your name:
Subject:
Your blog:
Your email:  (will not be displayed)
*Your message:

 
Please add 8 and 3 and type the answer here: