Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

What is the proper endpoint address to consume a custom sharepoint webservice service application from outside SharePoint?

I have written a service application based on a great example of David Taylor found here: http://blogs.msdn.com/b/dtaylor/archive/2010/06/11/calculator-service-source-code.aspx

I've tweaked it so I can deploy my own custom webservice as a service application. This works so far in the sense that I can see SharePoint creates a virtual website in IIS under the SharePoint Web Services application.

The purpose of my webservice is to facilitate the automated creation of site collections, sites, lists, folders, features activation, creation of sitecolumns and file handling.

My custom webservice should be called from our proprietary web application which is written in .NET, but not in SharePoint. Therefore I cannot use the SharePoint object model to consume the service.

The problem is that I don't know what the EndPoint address is to create a service reference in Visual Studio.

Any help would be appreciated.

share|improve this question
add comment

2 Answers

you need to add a webreference with the url + _vit_bin/Lists.asmx

so as an example:

I have a website with a webapplication called:

hello.mysite.com

to call its webservice I would go into the webapplication project (.net project), add a web reference with the url:

http://hello.mysite.com/_vit_bin/Lists.asmx

(tip: goto the website in a browser, and put in the url with the extention of /_vit_bin/Lists.asmx , it should redirect you to the webservice with a list of methods to use ;) , once your happy that it works...copy the url and use that!)

now it should resolve and you should have access to the lists.asmx webservice method! change lists.asmx to your custome one! You should be able to name it as you please to access the webservice, if you left it to the default name dont worry, just look in solution explorer and under webreference look at the name and use that! For simplicity i left it to the default name of webservice.

within the .net project you cant just directly call the webservice, you need some handshaking and by that i mean supply some credetials to access that webservice like so:

try
{
    webservice.Lists listService = new webservice.Lists();
    webservice.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
    webservice.Url = "http://hello.mysite.com/_vit_bin/Lists.asmx";

    var listNodes = webservice.GetList("Home");

    _isUserAuthenticated = true;
}
catch (Exception ex)
{
    //User does not seem to have access to the list.
    _isUserAuthenticated = false;
}

if your confused about the above, its simply getting the webservice object putting a . you then have access to the methods within. so I am using the list.asmx so i used webservice.list object to create a new instance to query against.

I then supply the credentials, you can explicitly put in the credentials or use as im using above! above is using the logged in user of the client pc! If the logged in user doesnt have access then an access denied exception will be thrown!

The last part is just getting the list on the sharepoint site called home ;)

its simple, here are some resources if you get stuck!

CredentialCache.DefaultCredentials Property

The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

To get the credentials as a NetworkCredential instance, use the DefaultNetworkCredentials property.

The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate". This method does not work for HTTP or FTP protocols.

http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials.aspx

CredentialCache.DefaultNetworkCredentials Property

The credentials returned by the DefaultNetworkCredentials property is applicable only for NTLM, negotiate, and Kerberos-based authentication.

The credentials returned by DefaultNetworkCredentials represents the authentication credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.

http://msdn.microsoft.com/en-us/library/system.net.credentialcache.aspx

HOW TO: Pass Current Credentials to an ASP.NET Web Service

http://support.microsoft.com/kb/813834

as noted by microsoft in the links that if its elevated than it will pass those credentials ;) thats if you dont want to use the client credentials ;) rather an elevated account that has access! If anyone has access and you dont want them to have access than i wouldnt elevate the privlages!

more examples on credentials:

http://forums.asp.net/t/1635458.aspx/1

share|improve this answer
add comment

There are ways you can use to deploy your custom Web service and expose endpoints using one of these methods:

  • ASMX Web service is the classic SOAP based and get deployed into the SharePoint hive (e.g. deployed into the _vti_bin/_layouts folder OR it can be also deployed to its own Web application domain;

Visual Studio handling of asmx web services

If it's a .asmx reference added as a legacy "Web Reference" in Visual Studio then all you need to do is set the Url property value of the proxy object before you call any web service methods. For example:

MyProxyASMXService proxy = new MyProxyASMXService();
proxy.Url = "web service url";
proxy.HelloWorld();
  • WCF service deployed into the _vti_bin/_layouts OR onto its own Web application domain.

Visual Studio handling of WCF services

If it's a .svc WCF service reference then you need to create your web service endpoint programmatically. For example:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("web service url");

ChannelFactory<IMyWCFWebService> factory = new ChannelFactory<IMyWCFWebService>(binding, endpoint);
IMyWCFWebService proxy = factory.CreateChannel();

proxy.DoWork();

P.S. SharePoint web services have few limitations so it is good to write your custom web service.

See code references

share|improve this answer
    
The webservice is deployed in the _vti_bin/layouts/<companyname>/<productname> folder. When I start the service (via Central Administration > Application Management > Manage services on server) an application is created under the web application 'SharePoint Web Services' in IIS. This application has an url like 'localhost:32843/9738c4eaa2894b94b46f822416a5b605';. I don't think that any client should use this url, but that this url is used by SharePoint internally. But which url do I need to use then? –  Robin May 16 '13 at 15:36
    
You're deploying it as a custom service application .Now you can go to Central Administration->Application Management->Configure service application associations and assign your new proxy group to the web application. In the code, just use url of Web application to get your custom service application. –  Falak Mahmood May 16 '13 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.