problem with SPServices.GetTemplatesForItem soap message slightly different in two environments...

Nov 5, 2012 at 3:03 AM
Edited Nov 5, 2012 at 3:08 AM

hi, i've been using the SPServices.GetTemplatesForItem method in my development environment no problem via

  var itemURL = documentURL;
    var testVar;
    $().SPServices({
        operation: "GetTemplatesForItem",
        item: itemURL,
        async: false,
        completefunc: function (xData, Status) {
            $(xData.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function (i, e) {
                testVar = $(xData.responseXML);
                // hard coded workflow name
                if ($(this).attr("Name") == wfName) {
                    var guid = $(this).find("WorkflowTemplateIdSet").attr("TemplateId");
                    if (guid != null) {
                        workflowGUID = "{" + guid + "}";
                    }
                }
            });
        }
    });
    return workflowGUID;
this works fine in the test/dev environment (i'm using SPSerivces-0.7.1.a.js) however i have found that this query will not work in production. I have actually stepped through the jquery.SPServices-0.7.1a.js code and have found that the soap messages generated for the call at line 1094, $.ajax({ (in sp services) are nearly identical:
not working SOAP Message:
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body>
<GetTemplatesForItem xmlns='http://schemas.microsoft.com/sharepoint/soap/workflow/' >
<item>http://trac-sp01/demo/demotown/InformationManagement/Governance/testabc.docx</item>
</GetTemplatesForItem></soap:Body></soap:Envelope>"
working SOAP Message: 
"<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'><soap:Body>
<GetTemplatesForItem xmlns=\'http://schemas.microsoft.com/sharepoint/soap/workflow/\' >
<item>http://sptest/sites/rmtm3/expiryTest/TLOGO.jpg</item>
</GetTemplatesForItem></soap:Body>
</soap:Envelope>"
i have checked all of my urls and they should be fine!.. THe thing i did notice is that the workingexample I notice that in my dev/test enviornment soap message has single quotes (') prepended by an escape character while in production this is not the case. Does anyone know why this escape character prepending is not happening, and is this the reason why my query is failing? I have been struggling on trying to get this to work all day and i'm pulling hairs!
Coordinator
Nov 5, 2012 at 3:17 AM

When it doesn't work, what does the returned XML look like? Is it showing some sort of error? Do you have the correct permissions in production to make the call you're making?

M.

Nov 5, 2012 at 3:45 AM
Edited Nov 5, 2012 at 4:20 AM

maybe it is some sort of permissions because i can't connect to the WSDL with SOAP UI (although i can with browser get to the wsdl).. i'll see if ican see any error message, i'm a site collection administrator so i'm not sure how my permissions could be blocked....

update.. i tested it by modifying my code as below, i can't step though the call but the variable response comes back with a value of "undefined", not too useful :(

<script type="text/javascript">
    var itemURL = "http://trac-sp01/demo/demotown/InformationManagement/Governance/testabc.docx"
    var workflowGUID;
    var response;
    var wfName="ExpireWF"
    $().SPServices({
        operation: "GetTemplatesForItem",
        item: itemURL,
        async: false,
        completefunc: function (xData, Status) {
            $(xData.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function (i, e) {
                testVar = $(xData.responseXML);
		response = $(xData.responseXML);
                // hard coded workflow name
                if ($(this).attr("Name") == wfName) {
                    var guid = $(this).find("WorkflowTemplateIdSet").attr("TemplateId");
                    if (guid != null) {
                        workflowGUID = "{" + guid + "}";
                    }
                }
            });
        }
    });
    alert(workflowGUID) 
<
Nov 5, 2012 at 4:59 AM
Edited Nov 5, 2012 at 6:14 AM

i tried to connect to a different web service with SOAPUI in the production environment (different service call) and it didn't work either

<script type="text/javascript">
 var thisSite = $().SPServices.SPGetCurrentSite();
 alert (thisSite);
</script>

the error thrown by soapui is "InvalidDefinitionException"

the interesting part is this call actually works in a CEWP, unlike the other calls... this is very confusing why only some would work but none could connect via soapUI...

As i'm not sure if this is an SPServices bug (my hunch is not) i'm have put a question out to the general sharepoint forum as to why i can't connect to my workflow web services with SOAP UI in the hopes that someone else has run into this...

http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/fcb49237-2222-4516-b82e-54a9426e6d05

Coordinator
Nov 5, 2012 at 1:31 PM
Edited Nov 5, 2012 at 5:49 PM

Yeah, it doesn't sound like SPServices, as it ought to work the same in the two environments, all other things being equal. If you can connect to the WSDL pages via the browser, then it must be something else about permissions, I think.

Any possibility that someone has tried to be "smart" and lock down the Web Services? This would break many other things, of course. Another thing to try is connecting to the Web Services in SharePoint Designer as a DataSource. SharePoint Designer uses the Web Services to talk to the server, so that may give you more clues.

M.

Nov 5, 2012 at 4:52 PM

ok so i tried to use sharepoint designer... if i connect to _vti_bin/webs.asmx?WSDL it works (shows data in data view), but if I connect to _vti_bin/workflow.asmx?WSDL, i get a non specific error in my data source...  once agian i have no problem browsing to the WSDL, but it seems like it doesn't like taking the GetTemplateForItem method ..

Nov 5, 2012 at 5:36 PM

actually found the message in the error logs when it fails from designer...

Leaving Monitored Scope (EnsureListItemsData). Execution Time=21.6217424281578 6e38edd6-693b-4a26-8d86-a7e94c681adb
11/05/2012 12:18:43.28  w3wp.exe (0x1714)                        0x1408 Document Management Server     Workflow Features              8026 Critical Workflow Soap: GetTemplatesForItem failed Item: http://trac-sp01/demo/demotown/InformationManagement/Governance/testabc.docx Object reference not set to an instance of an object.  Error:  Object reference not set to an instance of an object. 6e38edd6-693b-4a26-8d86-a7e94c681adb
11/05/2012 12:18:43.28  w3wp.exe (0x1714)                        0x1408 SharePoint Foundation          General                        avfx High     SOAP exception: System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.SharePoint.Workflow.SPWorkflowAssociation.get_SoapXml()     at Microsoft.Office.Workflow.WorkflowImpl.GenerateAssociationXMLForSOAP(IEnumerable`1 associations, SPWeb CurrentWeb, String ItemInfo)     at Microsoft.Office.Workflow.WorkflowImpl.GenerateTemplatesXMLForSoap(SPList list, SPListItem listitem, StringBuilder strRet, String strItemInfo)     at Microsoft.Office.Workflow.WorkflowImpl.GetTemplatesForItem(String item)     at Microsoft.Office.Workflow.Workflow.GetTemplatesForItem(String item) 6e38edd6-693b-4a26-8d86-a7e94c681adb

Coordinator
Nov 5, 2012 at 5:51 PM

Could it be a licensing difference between the two environments?

M.

Nov 5, 2012 at 6:08 PM

interesting point they are both enterprise server licenses, thanks for all your input so far..

Nov 5, 2012 at 11:17 PM

ok an update here i have isolated the problem to a specific site/site collection.  I guess my lack of knowledge of web services is hindering me a bit.  If I have a subsite in a site collection, ie http://trac-sp01/sites/demo/Governance, should i be connecting to http://trac-sp01/sites/demo/_vti_bin_/workflow.asmx?WSDL or should i be connecting to http://trac-sp01/sites/demo/Governence/_vti_bin/workflow.asmx?WSDL ?   Do the web services get exposed for each site or are they at the site collection level.  For some reason i can get the workfow web service to work in the root site of the site collection (http://trac-sp01/sites/demo/ ) but not in subsites... not sure why its broken in subsites..

Nov 6, 2012 at 5:00 AM

did some more testing and actuallyy its only one particular library in one particular site,  of course that is the site/library i selected to do my testing in so i'm lucky? i guess.  I have no idea why though.  I wonder what is wrong with this library...

 

Coordinator
Nov 6, 2012 at 11:27 AM
Edited Nov 7, 2012 at 12:39 PM

You do call the Web Services per site, not Site Collection. Or, if you're more of a server side guy per web, not site. So, in your example above, it would be  http://trac-sp01/sites/demo/Governence/_vti_bin/workflow.asmx. You may also be having problems with the protocol. You should always use relative addresses, like /trac-sp01/sites/demo/Governence/_vti_bin/workflow.asmx. This gets you around and http vs. https changes.

Is there anything about this one library that's set up differently than others?

M.

Nov 6, 2012 at 5:01 PM

i reviewed the library seettings with Sharepoint Manager and the only differences i could find were :

DefaultItemOpen - Prefer Client (production library, not working), browser(in test environment where its working)
Versioning -On (production library, not working),  On in test environment.

I don't think any of these are the real issue because i have it working in orther libraries in production that have these settings on...

thanks for the heads up on the relative url... actually i build my url in the javascript like:

         var oListItem = listItemEnumerator.get_current();
        var oFile = oListItem.get_file();
        var path = oFile.get_serverRelativeUrl();
        var fullitemurl = window.location.protocol + '//' + window.location.host + path;

i need to test this with https.  I tried passing just the path to my web service call (from the code above) but it didn't seem to work unless i passed the fullitemurl above.

thanks!