SOAP Web Server: "Input String Not In Correct Format"

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

doctorzeus

Thread Starter
Joined
Jun 10, 2010
Messages
277
Hello,

I have an issue with the SOAP web service I created, as I get the error:

Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.FormatException: Input string was not in a correct format.
When I try to call one of the functions like this it works perfectly:

Code:
WarehouseDistanceService.WarehouseDistanceServiceSoapClient warehouseClient;
String strA, strB;
int returnDistance;

warehouseClient = new WarehouseDistanceService.WarehouseDistanceServiceSoapClient();
strA = "London";
strB = "Manchester";

returnDistance = warehouseClient.DistanceBetween(strA, strB);
However I am reading strA and strB in from a database and then get the:
An unhandled exception of type 'System.ServiceModel.FaultException' occurred in mscorlib.dll

Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.FormatException: Input string was not in a correct format.

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
I assume there is probably some kind of special character in the String that I am not seeing that is not compatible with the web service. Any advice on how I can remove these/fix this?

Many Thanks

Dan
 
Joined
Jun 8, 2001
Messages
2,583
I suspect your putting the record id instead of the value in field or the field is wrong data type. We aren't seeing the code that fails?
 

doctorzeus

Thread Starter
Joined
Jun 10, 2010
Messages
277
Thanks for the reply, but I checked and am definitely getting the full warehouse names, here is my code:

Code:
void Run()
        {
            SQLClass sqlClass;
            WarehouseDistanceService.WarehouseDistanceServiceSoapClient warehouseClient;
            List<String> warehouses_origin, warehouses_dest;
            List<int> distances;
            String query, callback, tempWarehouseOrigin, tempWarehouseDest;

            //Setup and check connection
            sqlClass = new SQLClass(SQLValues.HOSTNAME, SQLValues.DATABASE, SQLValues.USERNAME, SQLValues.PASSWORD);
            if ((callback = sqlClass.TestSQLConnection()) != "")
            {
                Console.WriteLine("Error Cannot Connect To SQL Database:");
                Console.WriteLine(callback);
                return;
            }

            //Get all values
            query = "SELECT WarehouseID_Origin, WarehouseID_Destination FROM TransferOrder WHERE Completed = 0";
            warehouses_origin = sqlClass.SendDBCommand(query, 0);
            warehouses_dest = sqlClass.SendDBCommand(query, 1);

            //Convert all warehouseIDS into warehouse names
            for (int i = 0; i < warehouses_origin.Count; i++)
            {
                //Origins
                query = "SELECT Location FROM Warehouse WHERE WarehouseID = " + warehouses_origin[i] + ";";
                warehouses_origin[i] = sqlClass.SendDBCommand_CallBackAsOneString_NoComma(query, 0);
                //Destinations
                query = "SELECT Location FROM Warehouse WHERE WarehouseID = " + warehouses_dest[i] + ";";
                warehouses_dest[i] = sqlClass.SendDBCommand_CallBackAsOneString_NoComma(query, 0);
            }

            //Get all the distances from the soap web service
            distances = new List<int>();
            warehouseClient = new WarehouseDistanceService.WarehouseDistanceServiceSoapClient();
            for (int i = 0; i < warehouses_origin.Count; i++)
            {
                tempWarehouseOrigin = warehouses_origin[i];
                tempWarehouseDest = warehouses_dest[i];
                distances.Add(warehouseClient.DistanceBetween(tempWarehouseOrigin, tempWarehouseDest));
            }

        }
For info SQLClass is a simple class to handle the connection to the SQL server.

Also the Web Service Code:
Code:
[WebMethod]
        public int DistanceBetween(String originWarehouse, String destWarehouse)
        {
            String query, departureID, destinationID, distance_str;
            int distance;
            //Get the IDS
            query = "SELECT TownID FROM Town WHERE Town='" + originWarehouse + "';";
            departureID = ReadAccessDatabase_Int_OneStrNoComma(query, 0);
            query = "SELECT TownID FROM Town WHERE Town='" + destWarehouse + "';";
            destinationID = ReadAccessDatabase_Int_OneStrNoComma(query, 0);

            //Now Get the distance
            query = "SELECT DistanceInMiles FROM Distance WHERE Town1 = " + departureID + " AND Town2 = " + destinationID + ";";
            distance_str = ReadAccessDatabase_Int_OneStrNoComma(query, 0);
            distance = Convert.ToInt32(distance_str);

            return distance;
        }
Also here are the screens showing that the values do hold the actual strings of the warehouses: screenshot1 and screenshot2.

Many Thanks

DoctorZeus
 
Joined
Jun 8, 2001
Messages
2,583
by chance are your throwing decimal values into a int field? (I can't see those dropboxes from work pc)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top