×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

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?


3/14/2008 7:47 PM | # 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?
Gravatar
3/16/2008 2:39 AM | # 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 6:32 AM | # duplex binding
Can i use duplex binding with wcf services?
3/16/2008 11:42 AM | # 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 3:35 PM | # 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/17/2008 9:58 PM | # re: Calling web services with Silverlight 2
I'm also facing the same problem as Neeta.
3/18/2008 12:34 AM | # 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 4:47 AM | # 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 8:15 AM | # 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 9:29 AM | # 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 2:28 PM | # re: Calling web services with Silverlight 2
Thanks...good post!
3/19/2008 2:22 AM | # 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 6:40 AM | # 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/20/2008 3:33 PM | # 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/21/2008 11:12 AM | # 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/22/2008 1:03 PM | # 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:36 PM | # 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/24/2008 2:15 PM | # 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 :)
Gravatar
3/25/2008 10:41 AM | # 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/26/2008 8:49 AM | # 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 1:20 PM | # 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:24 PM | # 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:56 PM | # 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 2:08 PM | # 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 5:11 PM | # 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 6:39 PM | # 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/27/2008 12:09 PM | # 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:48 PM | # 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/29/2008 2:02 AM | # 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 7:09 AM | # 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)
4/2/2008 2:01 PM | # 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/3/2008 6:24 AM | # 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/8/2008 3:03 PM | # 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/9/2008 1:00 PM | # 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/22/2008 1:17 PM | # 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 11:36 PM | # 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/23/2008 1:22 AM | # re: Calling web services with Silverlight 2
@lakki: can you do a trace and see *what* request is returning a 404?
4/23/2008 2:48 AM | # 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 9:54 AM | # 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/24/2008 6:06 AM | # 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 9:35 AM | # re: Calling web services with Silverlight 2
Tim - you're a peach -- thanks.

FWIW -- the settings are on the "Start Options" tab --
4/28/2008 4:11 AM | # 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 8:15 AM | # 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 10:36 AM | # 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
5/1/2008 12:21 PM | # re: Calling web services with Silverlight 2
@ordwin: we don't support SoapExtension, but do support the newer ServiceModel.Channel stack.
5/14/2008 11:06 PM | # re: Calling web services with Silverlight 2
I am using WCF services and can't see a way of setting a behavoiur on the client as you would in a config file e.g.:

behavior name="XamlPrintWcfService.XamlPrintWcfIServiceBehavior"
dataContractSerializer maxItemsInObjectGraph=
"6553600"


How can this be done in C# code within the Silverlight Project. Note I'm using Silverlight 2.0 beta 1. I noticed that is does create the ServiceReferences.ClientConfig but it simply doesn't use this and you have to set it in code using your above example for WCF (you state it works for ASMX).
5/23/2008 12:58 AM | # re: Calling web services with Silverlight 2
Thanks Tim for a very useful post...

I have implemented a silverlight project using WCF and asmx webservice, I dont see much difference between the two implimentations. We are confused which way we should go..WCF or ASMX?

I am not sure how we will be able to handle Sessions(mainly for datastorage) in a WCF service. But i can do it easily in ASMX service.

We will have to use Sessios extensilvely in our Silverlight project as we have a login system and have few more data to be stored(like Connection string of a particular user).

We are also concerned about the performance of WCF or asmx service...

Also please suggest us a better code practice(architecture level) for Silverlight application.

My code structure is as follows.

SilverLight Class Library

<CompanyName>.Cui.Controls - this holds the usercontrols (xaml) that are used in Silverlight xaml pages(Hearder.xaml, DataGridSmall.xaml , pager.xaml etc)

Silverlight Client Project - xap

<CompanyName>.View- holds the xaml pages (Employees.xaml contains Hearder.xaml, DataGridSmall.xaml , pager.xaml )

SilverLight Web Project

<CompanyName>.Web- holds the aspx pages which in turn contains xap

WCF Class Library

<CompanyName>.Serviices- Contains services like EmployeesService which has methods Retrieve, Add, Update etc and is referenced in Silverlight Client Project. Retrieve method calls the Retieve method in BLL

Business Logic Layer

<CompanyName>.EmployeeManagement- Contains classes like Employees which has methods Retrieve, Add, Update etc. Add method uses Add method defined in Data Access Layer

Data Access Layer

<CompanyName>.DataAccess- Contains classes like Employees which has methods Retrieve, Add, Update etc. Uses LINQ to connect to DB.



Inorder to do a Retrieve employees on button click..what i do now are

1) Create instance of Service. Do the asyc call to WCF services

2) WCF Retrieve method creates object of BLL Employees class and call its Retrieve method

3) BLL Retrieve method creates object of DataAccess layer class

4) DataAccess Retrieve method calls the LINQ method returns the List


Thanks,
Anand
5/23/2008 5:38 AM | # re: Calling web services with Silverlight 2

Is SOAP support AJAX?
5/23/2008 8:18 PM | # re: Calling web services with Silverlight 2
@anand: I'd recommend using WCF. in the long run it gives you greater flexibility in exposing services over ASMX and can still use the same programming models.

@silvermouse: the question is really does AJAX support SOAP...and javascript doesn't know SOAP directly, but can parse XML. Using ASMX SOAP services with ASP.NET AJAX libraries will obfuscate much of the junk for you.
6/10/2008 8:55 AM | # re: Calling web services with Silverlight 2
@Kannan: sounds like it might be a format issue with the client polciy file. Attach a HTTP tool like Fiddler or Web Developer Helper to see if that is the case (which request is generating a 404).
6/16/2008 10:45 AM | # re: Calling web services with Silverlight 2
Tim, in the msdn documentation for beta 2, it says "For example, WS-Security is not directly supported, but the token-based authentication component of WS-Security can be emulated by injecting the appropriate SOAP headers into request messages." . How exactly can I inject a soap header into the request?
6/18/2008 2:08 AM | # re: Calling web services with Silverlight 2
Hi Tim,
I am new to silverlight. Thanks for your post . It gave me a good idea on invoking web services.
I am facing an issue on consuming a web service.On the server where web service is deployed, I have the clientaccesspolicy.xml. The message I got is as below:

System.ServiceModel.CommunicationException was unhandled by user code
Message="An error occurred while trying to make a request to URI 'http://localhost:8080/ProcessFlowDataProvider/PFData'. This could be due to a cross domain configuration error. Please see the inner exception for more details."
StackTrace:
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at testWS1.ws.PFDataClient.PFDataClientChannel.Enddp(IAsyncResult result)
at testWS1.ws.PFDataClient.testWS1.ws.PFData.Enddp(IAsyncResult result)
at testWS1.ws.PFDataClient.Enddp(IAsyncResult result)
at testWS1.ws.PFDataClient.OnEnddp(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
InnerException: System.Security.SecurityException
Message=""
StackTrace:
at System.Net.AsyncHelper.BeginOnUI(BeginMethod beginMethod, AsyncCallback callback, Object state)
at System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend(IAsyncResult result)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnSend(IAsyncResult result)
InnerException: System.Security.SecurityException
Message="Security error."
StackTrace:
at MS.Internal.InternalWebRequest.Send()
at System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation()
at System.Net.BrowserHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state)
at System.Net.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__3(Object sendState)
InnerException:


Could you please help me sorting out this problem.

Thanks
rishu
6/18/2008 6:55 AM | # re: Calling web services with Silverlight 2
@rishu: the underlying exception looks like a security exception -- ensure your authentication modules are correct and you aren't expecting any specific authentication.
6/18/2008 10:42 PM | # re: Calling web services with Silverlight 2
how do we pass user credentials to a WCF Service
when using Forms Authenitcation
6/19/2008 6:50 AM | # re: Calling web services with Silverlight 2
@mahesh: Take a look at http://silverlight.net/learn/learnvideo.aspx?video=56228
Gravatar
7/10/2008 12:57 AM | # re: Calling web services with Silverlight 2

Giving error like :

Additional information: [UnexpectedHttpResponseCode]
Arguments:Not Found
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.ServiceModel.dll&Key=UnexpectedHttpResponseCode
7/14/2008 8:05 AM | # re: Calling web services with Silverlight 2
A little bit late..

I have the same problem of ptoinson (4/2/2008 2:01 PM):

The app works great when runing using http. But, when it runs using https it fails as soon as i try to login (call WebService).
The same error he reported appears, as showed below:

"System.ArgumentException: via Parameter name: [InvalidUriScheme] Arguments:https,http Debugging resource strings are unavailable."

I didn't see any answer for this problem yet. =/

Anyone can help us please?
7/14/2008 9:59 AM | # re: Calling web services with Silverlight 2
Marcio: right now a service hosted under https must be called by a sivlerlight app hosted under https. that is the InvalidUriScheme error -- the protocols must match in beta 2
7/14/2008 10:35 AM | # re: Calling web services with Silverlight 2
Thanks tim, but i didn't understand.. =/
how can i do that?

the url that call the WebService i already change to "https"..
the iis is already configured to accept "https" too..
i was thinking that it's missing something to configure in WebConfig..

thank u for help.
8/11/2008 11:27 PM | # re: Calling web services with Silverlight 2
Hi,

Is it possible to do the Asynchronous callback in Webservices to silverlight application instead of getting the results at the end of the process completion. I need to send the feedback to the user as and when received the information from WCF service.

Please help me!!!

Thanks

Ganesh.
8/12/2008 8:39 AM | # re: Calling web services with Silverlight 2
Amir: I'm confused as all calls within Silverlight are asynchronous. You could do your stuff in the Completed event handler for WebClient or in the Async handler if you use HttpWebRequest.
Gravatar
8/13/2008 5:43 AM | # re: Calling web services with Silverlight 2
Hi,
When trying to test your source code I get an error regarding the "downloadstringcompletedeventargs"

I am using a silverlight webservice in my application (Silverlight Enabled WCF) after watching your video and reading through your blog. However, I receive an error "Type 'ReturnNoteNameCompletedEventArgs' is not defined" (ReturnNoteName is my function in my service.vb file) and then I receive a warning, "Custom tool warning: unable to load one or more of the requested types. Retrieve the loaderexceptions property for more information."

Any help would be greatly appreciated! Thanks.

8/15/2008 10:34 AM | # re: Calling Authenticated web services with Silverlight 2
I looked at your code and then tried a similar version of it against one of my existing web services. The web service is authenticated, not anonymous. When I call the web service from within Silverlight, I get the message "The remote server returned an unexpected response: (404) Not Found". When I plug this same code into a windows form I get this message: "The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'." And of course, if I call it from my browser, it works perfectly.

How do you call an authenticated web service from Silverlight?

I'm using the following code and I have linked the service reference in and done an Update Service Reference:

Dim URL As String = "http://localhost/CustXML.asmx"
ws = New wsCustXML.CustXMLSoapClient(New BasicHttpBinding(), New EndpointAddress(URL))
AddHandler ws.CustListXMLCompleted, AddressOf MyCustListXMLCompleted
ws.CustListXMLAsync(txtSearchTxt.Text, "Y")

Thanks!
8/15/2008 4:17 PM | # re: Calling web services with Silverlight 2
authenticated services which don't use the with information of the hosting app are not supported
8/18/2008 8:47 AM | # re: Calling web services with Silverlight 2
I don't understand your reply. Are you saying authenticated services are not supported? Or are you saying they are supported but only if you are in the same web domain? Or I just can't run this from VS2008 and call an authenticated web service? Can you give me a little more info on calling authenticated web services?
8/18/2008 8:50 AM | # re: Calling web services with Silverlight 2
Lyle: if you are calling an authenticated service from a non-authenticated site, it is not supported. What I mean by that is that if the site hosting the Silverlight app is anonymous and doesn't use authentication, then you won't be able to *provide* authentication to any subsequent call. Network calls from within Silverlight use the authentication information from the browser stack.
8/18/2008 9:37 AM | # re: Calling web services with Silverlight 2
I took my sample Silverlight page and put it in my authenticated site and it worked fine. So now the only question/issue I have then is -- how do I debug and run this from Visual Studio? I have the NTLM authentication turned on within IIS. The VS server is running on http://localhost:3605/ and my authenticated web service is running under IIS on http://localhost/. The authentication doesn't seem to pass between them, so it is possible to run this from VS and debug the app, or do I have to deploy everything to my IIS server?
8/18/2008 10:25 AM | # re: Calling web services with Silverlight 2
Lyle: to be safe I'd debug from the IIS server.
8/26/2008 3:06 AM | # re: Calling web services with Silverlight 2
Hi Tim Nirav here Again
I had downloaded your code when i tried to run it it shows
"AG_E_UNKNOWN_ERROR ",may be Iam missing some refernces,moreover I had SL2 beta 2 installed on my machine,then I tried creating simple SL app,with 1 textbox and 1 button,wen I write "Imports System.ServiceModel",VS doesnt allow.Is it like SL 2 beta 2 doesnt have it or wht.
8/26/2008 5:04 AM | # re: Calling web services with Silverlight 2
Hey I am Sorry
Neglect the above comment.As it is now working fine How and why I dont know.I am too much confused.I had never used WebService before(even in .Net Application).Can you please tell me some tutorial or guide that can tell me every thing in detail for creating a WebService and caling it from SL app.
8/26/2008 7:59 AM | # re: Calling web services with Silverlight 2
Nirav: here's some resources for you silverlight.net/.../videocat.aspx
8/27/2008 5:09 AM | # re: Calling web services with Silverlight 2
I get this error:
ProtocolException was unhandled by user code
The remote server returned an unexpected response: (404) Not Found.

I have a silverlight page where i want to choose a document and then call a WCF service to upload that document to MOSS.

It's the first time i try silverlight and wcf. maybe i should try something easier first, lol.

Has anyone seen this error before and do u have any clue what could be wrong. I've googled around and havent found any solution yet.

any suggestions are welcome.
8/27/2008 8:24 AM | # re: Calling web services with Silverlight 2
8/27/2008 10:08 PM | # re: Calling web services with Silverlight 2
Hi Tim

I am calling sharepoint lists web service in my silverlight app. I need to pass the logged in user's credentials to the web service. Is there any way to achieve it???

Waiting for your thoughts...
8/27/2008 10:14 PM | # re: Calling web services with Silverlight 2
Hi Tim
Thanks to you and some more to name,I am getting grip in building Sl app.And My first app is getting over.Now I had made a web-service,which does the function of sending mail.It works in simple .Net appl.But raising exception in SL.May be web-config can be the reason behind tht,coz all the parameters for SMTP Host are in web.config only.Wht did u say.
8/28/2008 4:54 AM | # re: Calling web services with Silverlight 2
Hey Think You are resting as it is night there.But I had got the solution.So please neglet the above comments .sorry if M wasting your time.
Thanks for that video It was just great n xplanative.
Gravatar
8/31/2008 3:28 AM | # re: Calling web services with Silverlight 2
Thanks for the example. I'm still new to .net development. Could you translate the following:

asmx.HelloWorldWithAsmxCompleted +=
new EventHandler(asmx_HelloWorldWithAsmxCompleted);
asmx.HelloWorldWithAsmxAsync(StringToEmit.Text);

into Visual Basic.

Thanks!
9/2/2008 3:30 AM | # re: Calling web services with Silverlight 2
Hello Tom
Here is your code in VB.

AddHandler asmx.HelloWorldWithAsmxCompleted, AddressOf asmx_HelloWorldWithAsmxCompleted
asmx.HelloWorldWithAsmxAsync(StringToEmit.Text)

Hope this helps.
For conversion of c# to VB just visit.
labs.developerfusion.co.uk/.../csharp-to-vb.aspx
9/2/2008 3:33 AM | # re: Calling web services with Silverlight 2
hi, great post.
i've created a service in asp.net web and a silverlight project in the same solution. the problem is silverlight cant discover webservie!
i tried build service(f5) it gives me the service address.
i tried to put address in address bar of add service window. then i clicked go this time it recognize my service. but when i click ok button an error occurs :
object reference not set to instace of an object

what is the problem?
Gravatar
9/9/2008 3:34 PM | # re: Calling web services with Silverlight 2
Hi,
Do you have the complete configutaion of the webserver for hosting the webservices regarding

the An error occurred while trying to make a request to URI 'localhost:50042/.../SimpleAsmx.asmx'. This could be due to a cross domain configuration error. Please see the inner exception for more details.

in your book.

As you see I am just beginning to get some experience in the Silverlight technology. And I am runing this example in the VS IDE.

Any help or reference are greatly appreciated.

Thanks
11/13/2008 3:51 AM | # re: Calling web services with Silverlight 2
Really good articale,
I added link to my Blog :blogs.microsoft.co.il/.../...erlight-2-client.aspx

Thanks,
Josh
11/28/2008 11:33 AM | # re: Calling web services with Silverlight 2
Hi timheuer,
Thanks for this wonderful article. It really helped me. I am stuck with a new issue now. I am calling a service.asmx hosted in a remote server in my silverlight application. Its giving me this error. I typed the URL in browser and service is running. I am able to call a webservice hosted in my IIS locally though.

System.Net.WebException: The remote server returned an error: NotFound ---> System.Net.WebException: The remote server returned an error: NotFound
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState)
at System.Net.AsyncHelper.<>c__DisplayClass2.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.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)


Appreciate if you could help me.
Thanks

11/28/2008 1:33 PM | # re: Calling web services with Silverlight 2
Sajitha: Take a look here: timheuer.com/.../...ross-domain-404-not-found.aspx and look at your traffic for more information about what is happening.
11/29/2008 5:30 AM | # re: Calling web services with Silverlight 2
I have Create a web service and added method which returns Dataset, and I am consuming this in the silverlight2.0

[WebMethod]
public DataSet GetAllTitlesssssss()
{
string ss = Server.MapPath("Database\\Nerd.mdb");
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=admin; Data Source=" + ss);
OleDbDataAdapter adp = new OleDbDataAdapter("select [S No], [Title] from [section]", conn);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}
------------------------------------------------------------------

When I remove this GetAllTitlesssssss() WebMethod then its works fine.
And When I add the above WebMethod then it give me error.

Error 2 The type or namespace name 'schema' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\Nerd 26Nov\Nerd_Drink_B_24Nov\Nerd_Drink_New\Service References\NerdTest\Reference.cs 74 17 Nerd_Drink_New


Can you suggest me what should be the problem?

Thanks
Rajneesh Kumar
12/8/2008 4:46 AM | # re: Calling web services with Silverlight 2
Thanks a lot for this example. I am new to silverlight. But i could create and call webservice refering ur example. Thanks a lot...
Gravatar
12/22/2008 9:18 AM | # re: Calling web services with Silverlight 2
I created a default WCF project, added a reference to my SilverLight project however, I dont get the wcf.HelloWorldFromWcfCompleted event by default showing up!

I do get wcf.HelloWorldFromWcfAsync, and corresponding Begin and End async functions, but no "completed" event.

Why wouldn't this show up?

12/25/2008 7:14 PM | # re: Calling web services with Silverlight 2
I have noticed that quite a few of you are having cross domain error when consuming an old or .Net 2.0 webservice in your SilverLight 2.0 application specially if that is running on a different server and you are trying to connect from your local machine, you get the error:

"..
This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details."

A simple solution to this is to add/create a new file called clientaccesspolicy.xml to your webservice.

Copy and paste the following in the new file:















Now upload this file to the server where the service is hosted. Update the service reference in your silverlight application. And give it a go.


12/25/2008 7:19 PM | # re: Calling web services with Silverlight 2
Seems like the code was removed, probably because of the tags: i will use &lt "<" and &gt ">"

&lt?xml version="1.0" encoding="utf-8" ?&gt
&ltaccess-policy&gt
&ltcross-domain-access&gt
&ltpolicy&gt
&ltallow-from http-request-headers="*"&gt
&ltdomain uri="*"/&gt
&lt/allow-from&gt
&ltgrant-to&gt
&ltresource path="/" include-subpaths="true"/&gt
&lt/grant-to&gt
&lt/policy&gt
&lt/cross-domain-access&gt
&lt/access-policy&gt
Gravatar
12/30/2008 2:43 AM | # re: Calling web services with Silverlight 2
Is it possible that mediaElement plays encrypt mp3?
3/4/2009 9:37 PM | # re: Calling web services with Silverlight 2
Hello I have use two port: Silverlight and one host for web service. I have tried using window forms or asp.net pages to use the web service and they both can run the service. When using the Silverlight application implemented using visual web developer and trying to call the service, it give me an error saying: The remote server returned an error Not Found. I have no idea how to solve it. It was not the cross domain problem coz I have tried to delete the cross domain file, it will generate another error saying my silverlight try to access a cross domain .....
3/4/2009 10:01 PM | # re: Calling web services with Silverlight 2
3/7/2009 12:55 PM | # re: Calling web services with Silverlight 2
I'm interested on handling connection errors. I have seens a lot of samples about building complex stuff to handle exception, but I would like to handle errors just like... your internet connection or the server went bananas.

Something like GMail does (right now my app gives a bad crash if some of that scenarios happens), Does SL has some easy way to control this errors?

Thanks
Braulio
3/10/2009 9:54 PM | # re: Calling web services with Silverlight 2
When using the Silverlight application implemented using visual web developer and trying to call the service, it give me an error saying: The remote server returned an error Not Found. I have no idea how to solve it. It was not the cross domain problem coz I have tried to delete the cross domain file, it will generate another error saying my silverlight try to access a cross domain .....
3/10/2009 10:27 PM | # re: Calling web services with Silverlight 2
curs -- please see timheuer.com/.../...ross-domain-404-not-found.aspx for helpful tools to identify what is really happening.
3/18/2009 10:38 AM | # re: Calling web services with Silverlight 2
I also just noticed that Tim's got a blog post that mentions the required "http-request-headers" attribute that I was missing: timheuer.com/.../...s-in-silverlight-2-beta-2.aspx
4/1/2009 11:05 AM | # re: Calling web services with Silverlight 2
Hey Tim,

Many thanks for this article. It cleared many things for me. Though there is still one question that i have for you which ofcourse is not related to WCF or web services. Shall i shoot it.
4/1/2009 11:44 AM | # re: Calling web services with Silverlight 2
amit -- feel free to ask away!
4/2/2009 10:45 AM | # re: Calling web services with Silverlight 2
Tim,

Here is the link to the Post that i have made on one of the forums. If the question I have posted is not clear to you, please email me i shall explain the entire scenario to you.
The link
http://silverlight.net/forums/t/85080.aspx

Looking fwd to +tive response from your end.
4/8/2009 7:21 AM | # re: Calling web services with Silverlight 2
can i have any option to this application code
4/8/2009 9:41 AM | # re: Calling web services with Silverlight 2
Anil there are several videos on this topic with source code available at http://silverlight.net/learn.
4/17/2009 10:26 AM | # re: Calling web services with Silverlight 2
For a half a day I was feeling like I was loosing it - none of the examples posted anywhere worked with my code. Here is what did:

1) Declared the Service Client WithEvents:

Private WithEvents m_ServiceClient As CarLoanServiceReference.CarServiceSoapClient

2) Created event handler Sub:

Private Sub MyCalculatePaymentCompleted(ByVal sender As Object, _
ByVal e As CarLoanServiceReference.MyCalculatePaymentCompletedEventArgs) Handles m_ServiceClient.MyCalculatePaymentCompleted

...

End of story... I do not get why everyone is creating a proxy delegate function for the event handler. Aside the fact that IT DOES NOT WORK in my case.
4/17/2009 11:00 AM | # re: Calling web services with Silverlight 2
OK, mistery solved. Official MS website had a bug for creating VB event delegate. However it still does not explain why nobody is simply declaring the Service object WithEvents.... :)
5/4/2009 3:17 PM | # re: Calling web services with Silverlight 2 -- InvalidUriScheme
I haven't seen an answer to the "System.ArgumentException: via Parameter name: [InvalidUriScheme]" here. Thanks to google, I found this and it got me going in the right direction: http://silverlight.net/forums/t/13275.aspx.

Cut to the chase, what you need to do is modify the transport security IF your endpoint is HTTPS (i.e. MyUri.Mode.Scheme == "https" ). See below.
bind.Security.Mode = BasicHttpSecurityMode.Transport;
5/9/2009 4:25 AM | # re: Calling web services with Silverlight 2
Nice artical..
5/11/2009 12:35 AM | # re: Calling web services with Silverlight 2
HI tim... Thanks for the post. I have a project that uses both webservice and wcf. I have done exactly what you have in you post, but im getting an error.

The error is "An excemption occured during the operation, making the result invalid".

can you help me with this...
5/19/2009 11:23 PM | # re: Calling web services with Silverlight 2
Bala -- check the actual request/response headers for a detailed exception.
5/24/2009 1:40 PM | # re: Calling web services with Silverlight 2
ligionare - sounds like an error in the service.
7/14/2009 11:52 AM | # re: Calling web services with Silverlight 2
Hi, help,...help..please help, I'm new in this topic about webservices and silverlight, my boss asigned me an application but actually I have maybe one week trying to solve the problem about communication
_______________________________________________________________________________
System.ServiceModel.CommunicationException: An error ocurred trying to make a request to URI....This could be due to attempting to acces a service in a cross domain way without a propper cross domain policy in place. or a policy that is unsuitable for SOAP service. You may need to contact the owner of the service to publish a cross domain policy file and to ensure it allows SOAP-related HTTP Headers to be sent.......etc..etc.....
________________________________________________________________________________
I already Did everithing but nothing NOTHING....fix the problem..please help...me I really apreciate
7/31/2009 1:36 AM | # re: Calling web services with Silverlight 2
Hi Tim, I hope you are still reading the comments :) I have a problem with a webservice since 4 days. Unfortunately no one was able ti help me on the forums yet. Maybe I have more luck here.
Is there somehow a way to define an eventhandler for each individual call of a webservice method? E.g. if I call my webservice myWebService(someCommand) I can add an eventhandler. For the next call on the same method I need another event handler. I descriped the problem a bit more in detail here: http://silverlight.net/forums/t/114833.aspx Any help is highly appreciated!
8/21/2009 8:44 AM | # re: Calling web services with Silverlight 2
Hi guys,
Here is a solution you are looking for: http://silverlightdataset.codeplex.com
Regards
Vitaly
9/8/2009 7:08 AM | # re: Calling web services with Silverlight 2
Thanks for the post!
Part of our team uses Adobe Flex in projects and we searched a solution to invoke WCF services. Changing binding to basicHttpBinding solved the problem.
Gravatar
1/13/2010 11:28 PM | # re: Calling web services with Silverlight 2
An error occurred while trying to make a request to URI 'http://localhost/EDServic/EDService.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

I added a file clientaccesspolicy.xml to my service project. This s a asmx service. Still I am getting this error when I am running this. What might be the error? I didn't set any network credentials.

Any help would be gre8
5/12/2010 7:31 AM | # re: Calling web services with Silverlight 2
Tim, I get an ASYNC_ExceptionOccured when trying to run the application after it has been hosted in the IIS. The app works fine locally when pointed to the local service but not when pointed to a service hosted on an IIS. The app uses WCF service. Your help is most appreciated. Thank you!
5/16/2010 10:32 PM | # Calling REST service
Hi,

Nice article and good explanation, but my problem is slightly different or may be its too common.

The problem statement is as follows:

How could we call a thrid part REST service using silver light client when this service wants credentials for authentication.

Ex. Twitter service want user name and password but through silver light i am not able to send the credentials hence it does not authenticate me and throw exception.

Kindly guide for the same

Intekhab
6/17/2010 6:37 AM | # re: Calling web services with Silverlight 2
@Intekhab
i think you have to use the ClientCredentials property on the proxy class (SomeWCFClient...)
7/27/2010 6:02 AM | # re: Calling web services with Silverlight 2
Hi Tim,How can I call web services in OOB for silverlight 3-4 ?
7/28/2010 3:10 AM | # re: Calling web services with Silverlight 2
I dont no:-]
9/1/2010 3:55 AM | # re: Calling web services with Silverlight 2
Hi Tim,
I have tried using your code which is as per the update-19 Mar. However, the call fails at base.endinvoke with the famous error :System.ServiceModel.CommunicationException: An error ocurred trying to make a request to URI....This could be due to attempting to acces a service in a cross domain way without a propper cross domain policy in place. or a policy that is unsuitable for SOAP service. You may need to contact the owner of the service to publish a cross domain policy file and to ensure it allows SOAP-related HTTP Headers to be sent
I have a clientaccess and cross domain xml file in my webservice and in www root. but no luck still.
I have basically published a WF project as a webservice and am trying to subscribe to this using Silverlight. Any clues
10/26/2010 2:16 AM | # re: Calling web services with Silverlight 2
hi

can any one pls explain the following line. I'm getting error in this.

WcfServiceClient wcf = new WcfServiceClient(bind, endpoint);

thank u..
1/28/2011 1:48 AM | # re: Calling web services with Silverlight 2
can anyone tell me what should be the value passed for the variables:

flickrApi
flikrImages
in the rest based call

thanks
9/14/2011 10:20 PM | # re: Calling web services with Silverlight 2
How can we access REST service hosted over HTTPS from silverlight with WebClient or HttpWebRequest
8/11/2014 5:38 AM | # re: Calling web services with Silverlight 2
How to consume web service hosted in https from silverlight?
This might be posted, please provide links. Thanks!

 
Please add 7 and 3 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.