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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
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("ResponseStatu s", Direction = SoapHeaderDirection.Out)]
public string HelloWorldEx(string name, int val)
{
ResponseStatus = new callStatus1();
try
{
//Your Code
// ResponseStatus.statusText. Add("Conne ction to DB successful"); //Some message you can add in.
}
catch
{
ResponseStatus.statusText. Add("Faile d");
ResponseStatus.statusText. Add("Error #1");
ResponseStatus.statusText. Add("Error #2");
}
}
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("ResponseStatu
public string HelloWorldEx(string name, int val)
{
ResponseStatus = new callStatus1();
try
{
//Your Code
// ResponseStatus.statusText.
}
catch
{
ResponseStatus.statusText.
ResponseStatus.statusText.
ResponseStatus.statusText.
}
}
ASKER
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.
ASKER
Many thanks for all your help.
ASKER
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?