Does SPServices support custom WebServices?

Mar 3, 2010 at 8:51 AM

I've created some WebServices which are also running in the _vti_bin (ISAPI) from SharePoint.

Is the SPServices functionality generic enough to support methods like:

Request:

POST /_vti_bin/MyService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.company.com/sharepoint/soap/MyApp/AddUser"

<?xml version="1.0" encoding="utf-8"?>
<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>
    <AddUser xmlns="http://schemas.company.com/sharepoint/soap/MyApp/">
      <loginName>string</loginName>
      <country>string</country>
      <domain>string</domain>
      <category>string</category>
      <component>string</component>
    </AddUser>
  </soap:Body>
</soap:Envelope>


Response

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<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>
    <AddUserResponse xmlns="http://schemas.company.com/sharepoint/soap/MyApp/">
      <AddUserResult>boolean</AddUserResult>
    </AddUserResponse>
  </soap:Body>
</soap:Envelope>

 

Coordinator
Mar 3, 2010 at 1:53 PM

Unfortunately, no it isn't.  This is because I need to build up the SOAP calls based on the known parameters for each operation.  However, if you look at how I'm framing the other Web Services, you should be able to extend or write your own small library to work in a similar way.

M.

Mar 4, 2010 at 3:43 PM

I've created the following javascript helper function:

function CallWebService(serviceName, methodName, parameters, complete, error) {

    var xmlParams = '';
    for (var key in parameters) {
        var value = parameters[key];
        xmlParams += "<" + key + ">" + value + "</" + key + ">\r\n";
    }

    var soapEnv =
                "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\r\n" +
                    "<soapenv:Body>\r\n" +
                        "<" + methodName + " xmlns='http://schemas.company.com/sharepoint/soap/MyApp/'>\r\n" +
                        xmlParams +
                        "</" + methodName + ">\r\n" +
                    "</soapenv:Body>\r\n" +
                "</soapenv:Envelope>";

    var host = window.location.protocol + '//' + window.location.host;

    $.ajax({
        url: host + "/_vti_bin/" + serviceName + ".asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=\"utf-8\"",
        complete: complete,
        error: error
    });
}

 

And this function can be called like:

CallWebService("MyService", "MyMethod",
                { "country": "NL",
                  "user": "server\user"
                },
                processResult,
                Error);

 

Coordinator
Mar 5, 2010 at 1:33 AM

Nice!

M.