Link to home
Start Free TrialLog in
Avatar of andrewmilner
andrewmilner

asked on

Web Services - onSuccess & Errors

I'm learning web services at the moment and have a need to get something into place.

I have produced a basic WebService which is taking 10+ strings and inserting into an SQL table.
[WebMethod]
public string InsertOrder

This as far as I can see allows me to do some checks on what is coming in and return an exception on an error.  But I can only output one error with this.

using XML:SOAP what should I be doing to output multiple errors and should I return a string success on completion or a bool.

Do you have some working code I could just drop into my Service1.asmx.cs file.
I'm not really familiar with having separate classes and referencing them etc.
Is there somethin I could just drop into this file that would output the XML:SOAP errors / success?

Many Thanks.
Andrew.
SOLUTION
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andrewmilner
andrewmilner

ASKER

I have implemented everything here bar the Your UI Code at the bottom which I couldnt really understand what was for.  whats the dhs referencing.

Also this doesnt appear to be doing anything more than what I was getting with.

catch(exception e)
return(exception.Message)

As it is still only returning one error.
What I'd like to do is to go through my entire strings of input and build the response errors as items within the SOAP response, and then simply return at the end of my web method all of the errors and only return success if error count = 0.

Is that what this code is meant to be doing?
Instead of passing a string, your normal webserice can return a custom class which has all details of the transaction.

The same is done and it is returned in the soap header by andrew. Extend his class "callStatus1" which has more properties to give the more than one result of ur transaction. Like a property which is a array of  statusText and one for Codes

dhs is nothing but in the client, is the name of web service proxy instance name.
Sorry the soad header sample referred by Harry and not by Andrew.
Could you help me get started in Extending callStatus1 with the array with some example code and example of sending an error from a catch :-)

Many thanks.
1) dhs is just the instance of the webservice.
2) Just you can change this part of your CallStatus1 Class,
private List<string> statusTextField = new List<string>();
        public List<string> statusText
        {
            get
            {
                return this.statusTextField;
            }
            set
            {
                this.statusTextField = value;
            }
        }
3) Whenever you encounter a catch block or wanted to add an error message just add it like,
[WebMethod]
        [SoapHeader("ResponseStatus", Direction = SoapHeaderDirection.Out)]
        public string HelloWorldEx(string name, int val)
        {
            ResponseStatus = new callStatus1();
try
{
//Your Code
// ResponseStatus.statusText.Add("Connection to DB successful"); //Some message you can add in.

}
catch
{
ResponseStatus.statusText.Add("Failed");
ResponseStatus.statusText.Add("Error #1");
ResponseStatus.statusText.Add("Error #2");
}
}
Must i only use one try catch block to make this work? i had a toy around yesterday trying it to output multiple lines in the XML:SOAP output but it still just kept outputting one line in the XML.
Many thanks for all your help.