c# - Catching a SoapException thrown by a WebService -


i wrote following service :

namespace webservice1 {     [webservice(namespace = "http://tempuri.org/")]     [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]     [system.componentmodel.toolboxitem(false)]     public class service1 : system.web.services.webservice     {         [webmethod]         public string test(string str)         {             if (string.isnullorempty(str))                 throw new soapexception("message", soapexception.clientfaultcode);             else                 return str;         }     } } 

and basic application test (one button calling test method on click event):

private void button1_click(object sender, eventargs e) {     servicereference1.service1soapclient ws = new windowsformsapplication1.servicereference1.service1soapclient();      try     {         ws.test("");     }     catch (soapexception ex)     {          //i never go here     }     catch (faultexception ex)     {         //always go there     }     catch (exception ex)     {      } } 

i'd catch soapexception thrown webservice, go faultexception catch block message:

system.web.services.protocols.soapexception: message @ webservice1.service1.test(string str) in [...]webservice1\webservice1\service1.asmx.cs:line 25

how catch real soapexception, , not faultexception? there miss in webservice?

i think main "problem" using wcf service reference connecting asp.net web service (.asmx).

the "easiest" way handle use web reference instead of wcf service reference on client. selecting "advanced" button on bottom of add service reference dialog, , add web reference on bottom of screen. believe using web reference should give soapexception.

the correct way (if want follow microsofts advice) publish wcf service instead of .asmx service. whole other chapter though..


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -