Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Silverlight and Webservice Exceptions

Posted on 2010-09-14
12
Medium Priority
?
856 Views
Last Modified: 2013-11-12
I am using silverlight 4 and calling a web service. The web service validates my data against business rules and if one fails it throws an exception. In silverlight 4 is there any way to catch the exception. Currently the only detail being sent back is "Not found"

Thanks,
Jim
0
Comment
Question by:jimseiwert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33674520
you need to have fault hadling in your WCF service
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33687734
I tried those but they did not work, Maybe I am missing something. below is an example of an error thrown in my webservice that I want to get the details of in silverlight. The throw exception detail is what I want to catch in silverlight on the return.
sub somefunction
       try
          'do something
       Catch ex As Exception
            Throw New Exception(ex.Message)
       End Try
end sub

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33689587
it should be Throw New FaultException(ex.Message)..if that doest work can you post you config file for service
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33693919
Ok I changed it to throw faultexception below is my web.config. Thank you again for looking at this
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <system.web>
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add name="silverlightFaults"
          type="SilverlightFaultBehavior.SilverlightFaultBehavior,
        SilverlightFaultBehavior, Version=1.0.0.0,
        Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <connectionStrings>
    <add name="SNC_OperationsConnectionString3" connectionString="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations" providerName="System.Data.SqlClient" /><add name="SNC_OperationsConnectionString" connectionString="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu" providerName="System.Data.SqlClient" />
  <add name="SNC_OperationsEntities" connectionString="metadata=res://*/Operations.csdl|res://*/Operations.ssdl|res://*/Operations.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="SNC_OperationsEntities1" connectionString="metadata=res://*/Operations.csdl|res://*/Operations.ssdl|res://*/Operations.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="SNC_OperationsEntities2" connectionString="metadata=res://*/OperationsDataModel.csdl|res://*/OperationsDataModel.ssdl|res://*/OperationsDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="Operations_Data_ModelContainer" connectionString="metadata=res://*/Operations_Data_Model.csdl|res://*/Operations_Data_Model.ssdl|res://*/Operations_Data_Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="SNC_OperationsEntities3" connectionString="metadata=res://*/OperationsModel.csdl|res://*/OperationsModel.ssdl|res://*/OperationsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&amp;E+KGxbg6WNjUu;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33693924
That was the web.config from the wevservice project. I assume that is the one you wanted
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33698879
i have modified your config as below ....

under services - > service i have added a sample you will need to modify it as per your contract
<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SilverlightFaultBehavior">
          <silverlightFaults/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add name="silverlightFaults"
          type="SilverlightFaultBehavior.SilverlightFaultBehavior,
        SilverlightFaultBehavior, Version=1.0.0.0,
        Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
     <services>
      <service behaviorConfiguration="WcfService.Service1Behavior" name="WcfService.SilverlightService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="WcfService.ISilverlightService"
                behaviorConfiguration="SilverlightFaultBehavior"  >
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

Open in new window

0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33701217
when I added your part of the web.config. I get the error message saying that this part is a invalid child element

      <behavior name="SilverlightFaultBehavior">
          <silverlightFaults/>
        </behavior>


Any ideas why?
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 33703105
can you post you web config file.... i cant find anything wrong with the one i posted other than the service contract names..which you would have changed while copying into your web config
0
 
LVL 2

Expert Comment

by:threesixteen
ID: 33810045
When I want to catch an exception in my silverlight clients from a webservice I'll put the exception handling in the webservice and in the event of an exception return the exception details to the client.

I then build logic into the client to handle that returned data and treat it as an exception..
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 33885707
I tried that and  still can not find anything wrong. Can you post a sample app that can catch and display a simple "throw new exception("test message")

Thank you
0
 
LVL 2

Accepted Solution

by:
threesixteen earned 2000 total points
ID: 33885895
Right - two things might be happening here, and without knowing what your webservice is doing in the backend it's tough to say for sure.  The first thing that's happening is that your webservice is truly returning no data, maybe because you're querying a database and nothing is getting found - or because an exception is happening in the web service.  The second thing is that an exception is happening in the web method, and since the exception is happening in the webservice there's really no exception in the silverlight client beyond no data getting returned from the web service.  

There's a couple of things you can do to troubleshoot from here:

1.) Call the webservice directly in a browser and try the method - depending on your IIS settings you'll either see a 500 or detailed exception info, in which case you can figure out what the problem is.  Best bet is to call the webservice on the server running the webservice itself, you should almost certainly get detailed info there.

2.) Wrap the web method you're using in a try/catch and in the event of an exception return some string either containing the exception data or something else that your silverlight client can deal with gracefully.

    <WebMethod()> _
    Public Function brokenFunction(ByVal inputString As String) As String
        Try
            'Some code that throws an exception belongs here
        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question