473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Webservice Exception

In the following webservice,If i put j=0,then 'Attempted to divide by zero' Exception should be displayed since in 'catch' block 'throw raisexception' is given.But it is showing 'Page cannot be displayed'.How to solve the error here ?

Expand|Select|Wrap|Line Numbers
  1.  
  2. public enum FaultCode
  3.  
  4. {
  5.  
  6.   Client = 0,
  7.  
  8.   Server = 1
  9.  
  10. }
  11.  
  12.  
  13.  
  14. [WebMethod]
  15.  
  16. public void GetException()
  17.  
  18. {
  19.  
  20.   try
  21.  
  22.   {
  23.  
  24.     int i = 1;
  25.  
  26.     int j = 0;
  27.  
  28.     int z;
  29.  
  30.  
  31.  
  32.     //generates the exception
  33.  
  34.     z = i / j;
  35.  
  36.   }
  37.  
  38.   catch (Exception ex)
  39.  
  40.   {
  41.  
  42.     throw RaiseException("GetException", "WSSoapException", ex.Message,
  43.  
  44.                       "1000", ex.Source, FaultCode.Server);
  45.  
  46.   }
  47.  
  48. }
  49.  
  50.  
  51.  
  52. //Creates the SoapException object with all the error details
  53.  
  54. public SoapException RaiseException(string uri, string webServiceNamespace,
  55.  
  56.                                 string errorMessage,
  57.  
  58.                                 string errorNumber,
  59.  
  60.                                 string errorSource,
  61.  
  62.                                 FaultCode code)
  63.  
  64. {
  65.  
  66.   XmlQualifiedName faultCodeLocation = null;
  67.  
  68.   //Identify the location of the FaultCode
  69.  
  70.   switch (code)
  71.  
  72.   {
  73.  
  74.     case FaultCode.Client:
  75.  
  76.       faultCodeLocation = SoapException.ClientFaultCode;
  77.  
  78.       break;
  79.  
  80.     case FaultCode.Server:
  81.  
  82.       faultCodeLocation = SoapException.ServerFaultCode;
  83.  
  84.       break;
  85.  
  86.   }
  87.  
  88.   XmlDocument xmlDoc = new XmlDocument();
  89.  
  90.   //Create the Detail node
  91.  
  92.   XmlNode rootNode = xmlDoc.CreateNode(XmlNodeType.Element,
  93.  
  94.                                 SoapException.DetailElementName.Name,
  95.  
  96.                                 SoapException.DetailElementName.Namespace);
  97.  
  98.   //Build specific details for the SoapException
  99.  
  100.   //Add first child of detail XML element.
  101.  
  102.   XmlNode errorNode = xmlDoc.CreateNode(XmlNodeType.Element, "Error",
  103.  
  104.                                         webServiceNamespace);
  105.  
  106.   //Create and set the value for the ErrorNumber node
  107.  
  108.   XmlNode errorNumberNode =
  109.  
  110.     xmlDoc.CreateNode(XmlNodeType.Element, "ErrorNumber",
  111.  
  112.                       webServiceNamespace);
  113.  
  114.   errorNumberNode.InnerText = errorNumber;
  115.  
  116.   //Create and set the value for the ErrorMessage node
  117.  
  118.   XmlNode errorMessageNode = xmlDoc.CreateNode(XmlNodeType.Element,
  119.  
  120.                                               "ErrorMessage",
  121.  
  122.                                               webServiceNamespace);
  123.  
  124.   errorMessageNode.InnerText = errorMessage;
  125.  
  126.   //Create and set the value for the ErrorSource node
  127.  
  128.   XmlNode errorSourceNode =
  129.  
  130.     xmlDoc.CreateNode(XmlNodeType.Element, "ErrorSource",
  131.  
  132.                       webServiceNamespace);
  133.  
  134.   errorSourceNode.InnerText = errorSource;
  135.  
  136.   //Append the Error child element nodes to the root detail node.
  137.  
  138.   errorNode.AppendChild(errorNumberNode);
  139.  
  140.   errorNode.AppendChild(errorMessageNode);
  141.  
  142.   errorNode.AppendChild(errorSourceNode);
  143.  
  144.   //Append the Detail node to the root node
  145.  
  146.   rootNode.AppendChild(errorNode);
  147.  
  148.   //Construct the exception
  149.  
  150.   SoapException soapEx = new SoapException(errorMessage,
  151.  
  152.                                            faultCodeLocation, uri,
  153.  
  154.                                            rootNode);
  155.  
  156.   //Raise the exception  back to the caller
  157.  
  158.   return soapEx;
  159.  
  160. }
  161.  
  162.  
  163.  
  164.  
Aug 23 '07 #1
0 915

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Davie | last post by:
I want to authorise a user of a web service by using the AuthHeaderValue for some reason I keep getting a null reference exception when I try to run the following code: It seems to work fine on a...
2
by: dan | last post by:
hi ng. i have a asp.net application which is client of an asp.net webservice. now i want to configure a custom error page (in case the sewrvice throws an exception) that provides the...
1
by: Nalaka | last post by:
Hi, I am testing with Visual studio 2005, web projects. Situation: I have one solution with two web projects, created as file system projects. (I am tesing using the built in server, not IIS)...
3
by: subha | last post by:
I have a HelloWorld webservice that works on my IE browser. But, when I add a webreference to it and call the HelloWorld method from my WindowsFormsApp (return in C#), I get error messages. The...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
0
by: Andrej | last post by:
hi, i have a java webservice which i would like to invoke from .net Application. i am able to generate the proxy class, but if i try to invoke the webservice i got an exception of type...
2
by: KaNos | last post by:
Hello world, I've made a webservice (c# v2) to install in a server IIS 6 on a Windows 2000 last SP. We can use the webservice in local, throw the pages wich present the methods, with a windows...
1
by: gihan | last post by:
Hi, I have a problem accessing remote webservice from my asp code. Instead of returning results, it returns list of web methods it has. Wonder where i'm doing wrong. Also note that, this is a...
7
by: Amirallia | last post by:
Hi, I consume my webservice with the IE browser and all is ok when I call it with one browser. But when I call it a the same time with two browsers, the IE page tells me that the apllication...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.