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



## doctorzeus (Jun 10, 2010)

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:


```
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


----------



## doctorzeus (Jun 10, 2010)

Anyone?


----------



## draceplace (Jun 8, 2001)

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 (Jun 10, 2010)

Thanks for the reply, but I checked and am definitely getting the full warehouse names, here is my 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:

```
[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


----------



## draceplace (Jun 8, 2001)

by chance are your throwing decimal values into a int field? (I can't see those dropboxes from work pc)


----------



## doctorzeus (Jun 10, 2010)

draceplace said:


> by chance are your throwing decimal values into a int field? (I can't see those dropboxes from work pc)


Nope, they are both full strings unfortunately.

Thanks

DoctorZeus


----------

