Returning a error message from within a .NET web service in C#

Please advise sample code for returning a error message from within a .NET web service in C#? . Thanks.


Please mark the post(s) that have helped you as "Answer"
0
thuhue
10/5/2007 7:07:56 AM
asp.net.xml-web-services 7071 articles. 0 followers. Follow

2 Replies
464 Views

Similar Articles

[PageSpeed] 24

refer the below article

http://msdn2.microsoft.com/en-us/library/ds492xtk(VS.71).aspx

 


Thanks
Sku
Please remember to click “Mark as Answer” on the post that helps you.
This can be beneficial to other community members reading the thread.
0
skurocks
10/5/2007 7:38:51 AM

Hi thuhue,

You can throw a SoapException in your webservice and add some information in it and catch the exception in your client . Here is my codes below, hope it is helpful to you.

 

1    [WebMethod]
2            public string HelloWorld()
3            {
4                string myNS = "Microsoft.Samples.XmlMessaging.WebServices.SoapExceptionSample";
5                XmlDocument doc = new XmlDocument();
6                XmlNode detail = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
7                XmlNode errorType = doc.CreateNode(XmlNodeType.Element,"ErrorType",myNS);
8                errorType.InnerText = "Validation";
9    
10               XmlNode lineNum = doc.CreateNode(XmlNodeType.Element,"Line",myNS);
11               lineNum.InnerText = "24";
12   
13               detail.AppendChild(errorType);
14               detail.AppendChild(lineNum);
15   
16               string errorMsg = "this is errorMsg";
17   
18               SoapException exc = new SoapException(errorMsg, SoapException.ClientFaultCode, "", detail);
19               throw exc;
20   
21               return "Hello World";
22           }
23   
24   private void button1_Click(object sender, EventArgs e)
25           {
26               localhost.Service1 ser = new WindowsApplication1.localhost.Service1();
27   
28               try
29               {
30                   string res = ser.HelloWorld();
31               }
32               catch(SoapException soapExc)
33               {
34                   string message = soapExc.Message;
35                   
36                   string show = soapExc.Detail.OuterXml;
37               }
38           }
Please remember to click “Mark as Answer” on the post that helps you.
 
0
zhangming870
10/9/2007 5:47:38 AM
Reply:

Web resources about - Returning a error message from within a .NET web service in C# - asp.net.xml-web-services

Returning - Wikipedia, the free encyclopedia
In retail , returning is the process of a customer taking previously purchased merchandise back to the retailer, and in turn, receiving a cash ...

Mark Zuckerberg Returning To TechCrunch Disrupt
Facebook Co-Founder and CEO Mark Zuckerberg took the stage at last year’s TechCrunch Disrupt conference in San Francisco, where he discussed ...

How-to: Improve the Experience for Returning Users
... – your inbox, your favorite news sources, or your friends’ activity. If you’ve integrated Facebook Login on your website, you can give returning ...

Search Twitter - emilia-clarke-not-returning
Sign in Sign up Search Refresh K. @ kikeurbina 1h Muy malas noticias: 'GAME OF THRONES' STAR EMILIA CLARKE (DAENERYS) NOT RETURNING FOR SEASON ...

Is the Returning CEO a Trend?
... well be wondering if it is a new trend for boards to reach back into their alumni ranks to bring back a CEO when a company is in Is the Returning ...

Returning fire - Flickr - Photo Sharing!
A U.S. Army soldier with the 101st Airborne Division returns fire with a M249 light machine gun during combat operations in the valley of Barawala ...

Marines Celebrate Returning Home With a Huge Pillow Fight Aboard the Airplane - YouTube
Visit http://WelcomeHomeBlog.com for more surprise military homecomings! In this clip, a group of marines celebrate their safe return home from ...

WWE’s Daniel Bryan on WWE 2K16, facing Brock Lesnar at WrestleMania, returning to the ring and life on ...
The four-time WWE world champion discusses whether it is right for Stone Cold Steve Austin to be the cover star of WWE 2K16, as well as who he ...

Damn Fine News of the Day: Kyle MacLachlan is Returning to ‘Twin Peaks’
In case you missed it, David Lynch announced on Twitter Monday that Kyle MacLachlan will reprise his role as Special Agent Dale Cooper in the ...

Injury not enough to keep official caught in crossfire from returning to action
The NRL match official caught in the crossfire of angry Bulldogs fans says he has no intention of stepping down from his role on the sidelines. ...

Resources last updated: 1/1/2016 7:35:40 PM