none
Inserting InfoPath Form Data int SQL Serve 2008 - Web Service Help

    Pergunta

  • I am trying to create a browser based form so that when the user clicks submit, the forms data is sent into a SQL Server 2008 database. I have done some research into this and know that I need some sort of web service between my database and the form. So I went ahead and created a web service based on code I have found online an deployed it. I can access the web service fine from my browser.

    Now I've gone into my InfoPath form and went to 'Submit Options', selected 'Allow users to submit this form' and selected 'Web Service' from the dropdown then 'Add'. Once I enter my web service address and click next it comes up with an error saying 'The Internet Address 'http://server.name/_vti_bin/InfoPathWebService.asmx?WSDL' is not valid.'

    So what have I done wrong? If I add the '?WSDL' to the end of the web service URL I also can't access it.What needs to be done to add that '?WSDL'?

    This is my web service code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;

    namespace test_service
    {
        /// <summary>
        /// Summary description for Service1
        /// </summary>

        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
        // [System.Web.Script.Services.ScriptService]
        public class Service1 : System.Web.Services.WebService
        {
            [WebMethod]
            public int InsertIntoTable(string product, float value)
            {
                string conStr = "Data Source=servername,port;Initial Catalog=dbname;User Id=username;Password=password;";

                SqlConnection sqlCon = new SqlConnection(conStr);
                sqlCon.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlCon;
                cmd.CommandText = "insert into Table(product,value) values ('" + product + "'," + value + ")";

                int i = cmd.ExecuteNonQuery();
                sqlCon.Close();
                return i;
            }
        }
    }

    The url for accessing my web service in the browser is like this: http://servername/_vti_bin/InfoPathWebService.asmx (notice it doesn't have the ?WSDL in the URL, is this the problem?)

    Thanks for any help :) I would really like to get this working without purchasing a web service or any plugin.

    • Editado tudorH terça-feira, 12 de junho de 2012 21:54 edited url info
    terça-feira, 12 de junho de 2012 21:48

Respostas

Todas as Respostas

  • Have you followed these steps to deploy your Web Service to SharePoint?

    http://msdn.microsoft.com/en-us/library/ms464040.aspx

    Make sure you follow the steps from top to bottom including renaming the wsdl and disco to .aspx and also copying them to appropriate location.

    The WSDL should work. Test the Web Service by creating a windows or console application and see if you can save to the Database.

    Regards,


    Ameet Phadnis (Alexander Open Systems) Please remember to click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    quarta-feira, 13 de junho de 2012 19:39
  • Have you followed these steps to deploy your Web Service to SharePoint?

    http://msdn.microsoft.com/en-us/library/ms464040.aspx

    Make sure you follow the steps from top to bottom including renaming the wsdl and disco to .aspx and also copying them to appropriate location.

    The WSDL should work. Test the Web Service by creating a windows or console application and see if you can save to the Database.

    Regards,


    Ameet Phadnis (Alexander Open Systems) Please remember to click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    Those are the instructions that I followed :) and I have just tried creating a console app that consumes the service, however, there is a problem...

    In the step "Generating and Modifying Static Discovery and WSDL Files" it tells you to remove the "-- <?xml version="1.0" encoding="utf-8"?> -- " and add in some other code. I have done this and renamed the files appropriately, copied to the _vti_bin directory and made the webservice discoverable in spdisco.aspx. Now when I try to access the web services online I get this error "The test form is only available for methods with primitive types as parameters." and my web service only uses strings and integers.

    Now if I try to create a windows forms application to consume the web service as the guide says, when I try to add the Web Reference to the project I get the following error:

    "The document at the url http://servername/_vti_bin/InfoPathWebService.asmx was not recognized as a known document type.
    The error message from each known type may help you fix the problem:
    - Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; chars"

    Any idea why I'm getting this error? Is it because in the wsdl and disco files I replaced the <?xml.... tag? I have no idea what to try next so any tips would be great!
    quinta-feira, 14 de junho de 2012 17:02
  • Managed to get the web service up and running. Went through the guide again and deployed on another server, seems to work fine on this one.
    sexta-feira, 15 de junho de 2012 17:04