25. September 2008 03:56
by Chakkaradeep
0 Comments
I am currently building a WCF service that has some Sharepoint code in it. The service uses wsHttpBinding. The service is hosted in Windows Server 2003 running IIS 6 with integrated windows authentication mode.
It was really strange to me when the service threw this (really a weird) exception:
The Web application at http://localhost/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application
The code which was throwing this exception was none other than:
1: using(
2: SPSite hostSite =
3: new SPSite(request.SiteCollectionUrl))
4: { ... }
Searching the web led me here
The solution was to set the the WCF Service's application pool's Identity to the same account Sharepoint website's application pool uses. Do not try to set the application pool to the same of Sharepoint as it might bring down the Sharepoint website when something goes wrong with the service!

How to verify this?
Good question :)
If you open up your WCF client configuration file, look for the <identity> tag inside the Endpoint configuration
1: <identity>
2: <userPrincipalName
3: value="mossservicedev@BUILD.DEV" />
4: </identity>
You can see that the identity is set to an account in the domain. Verify that with your application pool in IIS

If they both look the same, your Sharepoint code in the web service should work :)