jimseiwert
asked on
Silverlight and Webservice Exceptions
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
Thanks,
Jim
you need to have fault hadling in your WCF service
ASKER
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
it should be Throw New FaultException(ex.Message) ..if that doest work can you post you config file for service
ASKER
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&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="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&E+KGxbg6WNjUu;MultipleActiveResultSets=True"" 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="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&E+KGxbg6WNjUu;MultipleActiveResultSets=True"" 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="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&E+KGxbg6WNjUu;MultipleActiveResultSets=True"" 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="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&E+KGxbg6WNjUu;MultipleActiveResultSets=True"" 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="Data Source=snccostpoint;Initial Catalog=SNC_Operations;Persist Security Info=True;User ID=WT_Operations;Password=G&E+KGxbg6WNjUu;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>
ASKER
That was the web.config from the wevservice project. I assume that is the one you wanted
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
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>
ASKER
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="SilverlightFaultBeha vior">
<silverlightFaults/>
</behavior>
Any ideas why?
<behavior name="SilverlightFaultBeha
<silverlightFaults/>
</behavior>
Any ideas why?
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
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..
I then build logic into the client to handle that returned data and treat it as an exception..
ASKER
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
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.