SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Webservice - SPList Problem

Last post 08-07-2008, 2:48 PM by alex350r. 9 replies.
Sort Posts: Previous Next
  •  08-06-2008, 12:24 PM 12747

    Webservice - SPList Problem

    Hi All,

    Ive got a webservice which takes two inputs - currency string and value integer,  looks up some values from an SPList and multiplies these by the value, basically converts an amount into different currencies. I can debug the webservice on the local machine and it works fine, however when I try from infopath I always get -

    "InfoPath cannot connect to a data source" and that the query cannot be run, it does not give a particular reason why.

    If I remove SPList from the webservice, it seems to work ok, any ideas?

    Code for the webservice is below.

    Thanks,

    Alex

      [WebMethod]
        public decimal SalesTransactConversion(string fromCurrency, int SalesValueTransact)
        {
            //Create a new SPsite (SharePoint Site)

         SPSite site = new SPSite("http://ukhqsptest002:45697/");


            //Open the Root Webs

         SPWeb web = site.OpenWeb();

            web.AllowUnsafeUpdates = true;

            //Declare our Conversion Custom List

         SPList conversionlist = web.Lists["Conversion"];

     

            //Create an SPQuery that we will use to query the list

          SPQuery query = new SPQuery();

           query.Query = "<Where><And><And><Eq><FieldRef Name='Title' /><Value Type='Text'>EUR</Value></Eq>" +
                          "<Leq><FieldRef Name='Effective_x0020_From' /><Value Type='DateTime'>2008-07-25T00:00:00Z</Value>" +
                          "</Leq></And><Geq><FieldRef Name='Effective_x0020_To' /><Value Type='DateTime'>2008-07-25T00:00:00Z</Value>" +
                          "</Geq></And></Where>";

            //Get all items in the list matching our query and put them into a collection
           
            SPListItemCollection items = conversionlist.GetItems(query);

            //Declare our Conversion Rate and Round Amount Variables

            string convertratestring;
            string roundvaluestring;

            //Set it to a Sample Value

            convertratestring = "Something";

            roundvaluestring = "Something";

            //Iterate through the items in the collection and set our string to the Convert Rate of the item and our Round Amount

            foreach (SPListItem item in items)
           {
                convertratestring = item["Convert Rate"].ToString();
               roundvaluestring = item["Round Value"].ToString();
           }

            //Convert the Conversion Rate from string to decimal


            decimal convertratedecimal;

            convertratedecimal = Convert.ToDecimal(convertratestring);

            //Convert the Round Value from string to integer

            int roundvalue;

            roundvalue = Convert.ToInt16(roundvaluestring);

            //Convert our Sales Value Transaction amount into a decimal
           
            decimal SalesValueTransactdec;

            SalesValueTransactdec = Convert.ToDecimal(SalesValueTransact);

            //Create a decimal in which to store our Sales Value Base amount

            decimal SalesValueBasedec;

            //Multiple the Sales Transaction amount by the Convert Rate and return the Sales Value Base Amount

            SalesValueBasedec = decimal.Multiply(SalesValueTransactdec, convertratedecimal);

            //Round the Sales Value Base Amount to the Required Round Value

            SalesValueBasedec = decimal.Round(SalesValueBasedec, roundvalue);

            //Return the Sales Value Base Amount

            return test;


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
  •  08-06-2008, 12:40 PM 12749 in reply to 12747

    Re: Webservice - SPList Problem

    Alez,

    Are  you trying to access from a form running in the infoPath client or from a web Server based form.

    Is there anything in the 12/logs relating to the form? (E.g. if you're running a server based form, look for Forms Server errors in the logs.) I've seen this error before where it's not happy with the list name and you might need to retrieve it by Guid.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-06-2008, 1:45 PM 12753 in reply to 12749

    Re: Webservice - SPList Problem

    Hi Paul,

    Im not running it as a server based form so there is no logs to check im afraid.

    I am simply running/previewing the form from my own laptop. Ive got full permissions on the sharepoint site/list in question.

    Any other ideas?

    How can I get the list guid? I could try that

    Cheers

    Alex


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
  •  08-06-2008, 2:46 PM 12758 in reply to 12753

    Re: Webservice - SPList Problem

    Go to the site that you're connecting to, bring up the list and then choose list settings. The Guid will be buried in the QueryString in the URL at the top of your browser screen. something like ?ListID=nnnnnnnnn"

    Are you running the SharePoint server on your laptop? Check the eventvwr and the 12/logs just in case on the target server.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-06-2008, 3:00 PM 12761 in reply to 12758

    Re: Webservice - SPList Problem

    Hi Paul,

    Ive not got SharePoint server on my laptop, it is on a virtual server, I have simply designed the form and am previewing it. There is nothing relevant in the 12 logs on the server but in the eventvwr are a few of the following:

    Event Type: Warning
    Event Source: ASP.NET 2.0.50727.0
    Event Category: Web Event
    Event ID: 1309
    Date:  06/08/2008
    Time:  14:52:59
    User:  N/A
    Computer: UKHQSPTEST002
    Description:
    Event code: 3005 Event message: An unhandled exception has occurred. Event time: 06/08/2008 14:52:59 Event time (UTC): 06/08/2008 13:52:59 Event ID: fd087f8a04e541e4b923c1034ddef1e8 Event sequence: 12 Event occurrence: 1 Event detail code: 0  Application information:     Application domain: /LM/W3SVC/3430009/Root-3-128625043719797911     Trust level: Full     Application Virtual Path: /     Application Path: C:\Inetpub\wwwroot\webservices\ConversionService\     Machine name: UKHQSPTEST002  Process information:     Process ID: 4900     Process name: w3wp.exe     Account name: SEWS-E\srvsesapppool  Exception information:     Exception type: HttpException     Exception message: Request format is unrecognized.  Request information:     Request URL: http://ukhqsptest002:4427/service.asmx     Request path: /service.asmx     User host address: 192.168.53.176     User:      Is authenticated: False     Authentication Type:      Thread account name: SEWS-E\srvsesapppool  Thread information:     Thread ID: 5     Thread account name: SEWS-E\srvsesapppool     Is impersonating: False     Stack trace:    at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
       at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
       at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
       at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    I have tried using the list GUID but it doesnt seem to work, the list guide is: 7B2A7F0F62%2D9207%2D46F0%2DADB6%2D924CAA3BF8F4

    Cheers,

    Alex


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
  •  08-06-2008, 3:57 PM 12770 in reply to 12761

    Re: Webservice - SPList Problem

    Hmm.. is this definately your code causing the exception as the URL is different (port 4427?).

    I take it your webservice is created as a standard ASP.NET webservice and isn't installed into Sharepoint itself? I'm not sure if this will limit the access you have to the SP object model. Given that you can instantiate Site and Web, it would appear not..

    Also you might need to reformat the List Guid and replace the %2D with -

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-06-2008, 4:15 PM 12772 in reply to 12770

    Re: Webservice - SPList Problem

    Yep, I got that error log from the server on which the code/webservice is running. I can run the webservice fully locally on the server and it works fine.

    But when im calling it from my machine using infopath it doesnt work. I tried removing the %2D and replacing with - but i get the following error:

    System.ArgumentException: Value does not fall within the expected range.
       at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)
       at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)
       at Service.SalesTransactConversion(String fromCurrency, Int32 SalesValueTransact) in c:\Inetpub\wwwroot\webservices\ConversionService\App_Code\Service.cs:line 33

    I was wondering if it might be something to do with how infopath serialises/deserialises the xml data perhaps?

    I can indeed use all the SP object model within the webservice after referencing the sharepoint dll.

    Any other ideas? I have been trawling the net for someone with a similar problem, if I cant get it fixed i need to think of another method to submit some infopath variables into some code/sharepoint, get it to query a list and then perform mathematical calculations on the values before returning them to infopath/sharepoint.

    Cheers for all your help so far :-)

    Alex


     


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
  •  08-06-2008, 4:21 PM 12777 in reply to 12772

    Re: Webservice - SPList Problem

    Can you connect to the web service from your machine and test it from IE, not from infoPath? I'm not sure if this would be affected by the Double Hop issue, if it is, then the only fix for this would be to implement Kerberos.

    Paul.


    www.myfatblog.co.uk
    MCTS: WSS 3.0
    MCTS: MOSS 2007
  •  08-06-2008, 4:33 PM 12778 in reply to 12777

    Re: Webservice - SPList Problem

    Unfortunately not because webservices can only be invoked from the local machine, I can go to the webservice main screen but not invoke the actual method.

    Thanks,

    Alex


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
  •  08-07-2008, 2:48 PM 12817 in reply to 12778

    Re: Webservice - SPList Problem

    BUMP, any ideas anyone? really stuck on this one.

    Thanks,

    Alex


    My New SharePoint Blog - http://sharepointcoding.wordpress.com

    MCP: Windows XP
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems