On my devbox, I have created an empty SharePoint 2010 solution/Added new SPI of type WCF Service (CKSDev)/Deployed it. The files end up nicely in the ISAPI/MyProjectFolder
Now according to some blogs out there all you need to do is deploy and then browse your web service adding the /mex in the end to see if it worked, i.e http://myserver:666/_vti_bin/spwcf/sampleservice.svc/mex
This works fine, returning the wsdl definition.
But when trying to add a new servicereferece in a test consoleapplication the magic stops.
When I try to add http://myserver:666/_vti_bin/spwcf/sampleservice.svc/mex or http://myserver:666/_vti_bin/spwcf/sampleservice.svc i get the following error:
There was an error downloading 'http://myserver:666/_vti_bin/spwcf/SampleService.svc'.The request failed with HTTP status 400: Bad Request.Metadata contains a reference that cannot be resolved: 'http://myserver:666/_vti_bin/spwcf/SampleService.svc'.The HTTP
request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.The remote server returned an error: (401) Unauthorized.If the service is defined in the current solution, try building the
solution and adding the service reference again.
I've been poking around this problem for quite a bit. Anyone else experienced this? Or not experienced this?
Found a solution (but I'm still curious if anyone got this working without my customization of the .svc-file)
In the .svc-file i removed the Factory-attribute
Added a web.config and deployed to the same place as .svc-file.
<?xml version="1.0" encoding="utf-8" ?>
<binding name="BasicHttpBinding_ISampleService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="true" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483640" maxBufferPoolSize="2147483640" maxReceivedMessageSize="2147483640"
messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
<service name="SPWCF.SampleService" behaviorConfiguration="SampleServiceBehavior">
<endpoint address="" contract="SPWCF.ISampleService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService" />
<customErrors mode="Off" />
Just change the deployment target of the .svc file to ISAPI (remove the "MyProject"-folder the SPI adds) and leave the factory attribute. With the factory attribute in place, the SharePoint foundation service factory will configure the appropriate
endpoints for your service in run time automatically. Sweet!
To use the service, add a service reference in a client program (WinForm, Consoleapp..whatever) add /mex in the end such as:
Done and ready to use
Nov 2, 2011 at 9:36 PM
Thanks for posting up some advice on the service issues. At the time of creating the svc SPI there was little information about some issues around the use of the factory so i'm glad to see that it could be something as simple as the 'extra' folder in the
deployment location. Do you have a preference whether the SPI should drop the specific folder and use a factory or remain sub foldered but with a local web.config?
Nov 3, 2011 at 4:09 PM
Edited Nov 3, 2011 at 4:10 PM
Having the same (or a similar) issue.
Start with Empty SharePoint Project -> Add a (CKSDev) WCF Service -> Deploy. The /mex endpoint works fine.
The error I get when attempting to invoke the HelloWorld() method via WcfTestClient.exe is:
The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 227 bytes
of the response were: 'A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - Either a required impersonation level was not provided, or the provided impersonation level is invalid.)'.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at :
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
So, the server is throwing an error here over authentication/impersonation. If I remove the 'MyProject' folder from the .svc deployment target as suggested by Martin above, I get the same error.
Nov 8, 2011 at 12:32 PM
Edited Nov 8, 2011 at 1:52 PM
I'm not sure. I think there are scenarios where both approaches apply. The best solution would probably be supporting both, dependent on what requirements you will have when developing. But this is my guess. Here is the msdn article
describing wcf services SharePoint 2010.