1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by doctorzeus, Mar 12, 2015.

Thread Status:
Not open for further replies.
Advertisement
  1. doctorzeus

    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:

    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:
    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
     
  2. doctorzeus

    doctorzeus Thread Starter

    Joined:
    Jun 10, 2010
    Messages:
    277
    Anyone?
     
  3. draceplace

    draceplace

    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?
     
  4. doctorzeus

    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
     
  5. draceplace

    draceplace

    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)
     
  6. doctorzeus

    doctorzeus Thread Starter

    Joined:
    Jun 10, 2010
    Messages:
    277
    Nope, they are both full strings unfortunately.

    Thanks

    DoctorZeus
     
  7. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1144640

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice