[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3210
  • Last Modified:

infopath 2007 submit data via web service to sql 2008

I am trying to submit data from an infopath 2007 form to an sql 2008 database table named "employees".  I have 5 columns in the table which i want populated when the user pushes the submit button on the form.  I made a web service to help with the data transfer which infopath connects to.  the problem i have is that when i push the submit button, i get an error on the form telling me  the following.  After the infopath error message, I have included my web service code. i would appreciate some direction in what i am doing wrong.  thank you.

The query cannot be run for the following DataObject: AddNewEmployee
InfoPath cannot run the specified query.
The SOAP response indicates that an error occurred:

System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 424). ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt32(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_Employee(Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_AddNewEmployee()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

WEBSERVICE CODE (C#)

 using System;
 using System.Web;
 using System.Web.Services;
 using System.Data;
 using System.Data.SqlClient;

public class Service : System.Web.Services.WebService
{
    public struct Employee
    {
        public int EmployeeNumber;
        public String Title;
        public String FirstName;
        public String LastName;
        public Decimal Salary;
    }

    [WebMethod]
    public int AddNewEmployee(Employee employee)
{
  int rowsAffected = 0;
  using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=Online_Content;User ID=user;Password=******"))
  {
    SqlCommand cmd = new SqlCommand("INSERT INTO Employees " +
      "(EmployeeNumber, Title, FirstName, LastName, Salary) " +
      "VALUES(@EmployeeNumber, @Title, @FirstName, @LastName, @Salary)", conn);

    cmd.Parameters.AddWithValue("@EmployeeNumber", employee.EmployeeNumber);
    cmd.Parameters.AddWithValue("@Title", employee.Title);
    cmd.Parameters.AddWithValue("@FirstName", employee.FirstName);
    cmd.Parameters.AddWithValue("@LastName", employee.LastName);
    cmd.Parameters.AddWithValue("@Salary", employee.Salary);

    conn.Open();
    rowsAffected = cmd.ExecuteNonQuery();
  }

  return rowsAffected;
  }
}
0
bwierwi
Asked:
bwierwi
1 Solution
 
clayfoxCommented:
It is way simpler to get the web services prebuilt.

I would download the free suite from Qdabra, even just to test it and see how they do it.

Personally it is way simpler and easier since then trying to build one yourself that does everything theirs does.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now