locked
Custom Web Service with CKS Issue RRS feed

  • Question

  • Hello,

    I'm developing a Custom Web Service for Sharepoint 2010 with the CKS Developer Kit . The problem is I have to deploy it in a Web Application through port 443 so it's a https connection.

    When using the CKS dev in Visual Studio it does not allow you to modify the web.config file of the service, so I don't know where to apply the modifications for using https connection with the service.

    Have anyone worked with CKS? Any ideas?

    Thank you so much!

    Monday, August 1, 2011 9:00 AM

Answers

  • How did you decide the binding? Did you add a service reference to your app and examine the generated binding? I don't think MultipleBaseAddressBasicHttpBindingServiceHostFactory supports WSHttpBinding - the generated binding at the server side will be BasicHttpBinding and hence if you are specifying WsHttpBinding at the client side you will get the bindings mismatch error. Have you tried BasicHttpBinding? The specified transport security mode will then tell the client it should be over HTTPS.
    Ceej
    www.3guysonsharepoint.com

    • Marked as answer by Marc Jordana Monday, August 1, 2011 3:20 PM
    Monday, August 1, 2011 1:11 PM
  • Ok, I was doing the connection in the wrong way.

    First of all I was using WsHttpBinding when it was not needed, so now I use BasicHttpBinding (as ceej_3GuysonSharePoint said).

    Then I have to provide the ClientCredentials and finally set the ServerCertificateValidationCallback to return allways true.

    Now is running ok! This is the connection I have:

    CustomWebServiceClient proxy = new CustomWebServiceClient("BasicHttpBinding_ICustomWebService");
    
    proxy.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "passwordString", "domainName");
            proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            
    ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return (true); };
    
    Selector(proxy);
    


    Even though I'll mark your answers as correct.

    Thank you for the help!

    • Marked as answer by Marc Jordana Thursday, August 8, 2013 12:01 PM
    Monday, August 1, 2011 3:19 PM

All replies

  • When the service you have developed is packaged as a WSP and deployed to your specified site, it will be copied to a subdirectory of the ISAPI folder in the SharePoint Root (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI). This subdirectory will match the name of your project. The custom service will then be available to client applications at the endpoint address http://<Your server name>/_vti_bin/<Your project name>/<Your Service Name>.svc/mex.

    Hopefully this will help you understand that the configuration of your service is separate to that of your web application that hosts the SharePoint site collection/site. To ensure you have an HTTPS connection you should configure your web application to run over HTTPS - this is done when you set up your web application. You can extend an existing web application to run over HTTPS but obviously this would mean that you still have an HTTP entry point to that application too(assuming that you set it up with HTTP originally).


    Ceej
    www.3guysonsharepoint.com
    Monday, August 1, 2011 9:10 AM
  • Thank you for the fast response,

    but I already have the https Web Application. The problem is when implementing the web service I'm not allowed to modify the web.config file, where it is suposed to be the settings for the https binding connection.

    The service runs perfectly in a http connection (I tested it), the problem is moving the service to https.

    Monday, August 1, 2011 9:24 AM
  • Why do you need to edit the web.config? The /_vti_bin virtual directory maps to the ISAPI folder of the SharePoint root and so will be available under both HTTPS and HTTP depending on you SharePoint/IIS configuration. Are you not specifying a service factory in your .svc file to enable dynamic configuration? This will remove the requirement to edit the web.config.
    Ceej
    www.3guysonsharepoint.com
    Monday, August 1, 2011 9:37 AM
  • That's what the service .svc looks like:

    <%@ ServiceHost Language="C#" Debug="true"
      Service="CustomWebService.CustomWebService, $SharePoint.Project.AssemblyFullName$" 
      CodeBehind="CustomWebService.svc.cs"
      Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    

    So, you say I have to remove the Factory? And then what?

    Thank you!

    Monday, August 1, 2011 10:08 AM
  • No, don't remove it. With this in place you are instructing SharePoint to dynamically configure the service. At run time, the SharePoint Foundation service factory should configure the appropriate endpoints for your service automatically. What error do you get if you try to connect to the service on your HTTPS SharePoint site?
    Ceej
    www.3guysonsharepoint.com
    Monday, August 1, 2011 10:38 AM
  • It says "the client and the server bindings mismatch".

    I'm using a Console Application to test the service, that's the connection I'm using:

     

    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.Transport;
            
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
    EndpointAddress endpoint = new EndpointAddress(websiteUrl + "_vti_bin/CustomWebService/CustomWebService.svc/mex");
    CustomWebServiceClient proxy = new CustomWebServiceClient(binding, endpoint);
    
    proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
    
    Selector(proxy);

     

    What's wrong here?

     

    Thank you!

    Monday, August 1, 2011 10:50 AM
  • How did you decide the binding? Did you add a service reference to your app and examine the generated binding? I don't think MultipleBaseAddressBasicHttpBindingServiceHostFactory supports WSHttpBinding - the generated binding at the server side will be BasicHttpBinding and hence if you are specifying WsHttpBinding at the client side you will get the bindings mismatch error. Have you tried BasicHttpBinding? The specified transport security mode will then tell the client it should be over HTTPS.
    Ceej
    www.3guysonsharepoint.com

    • Marked as answer by Marc Jordana Monday, August 1, 2011 3:20 PM
    Monday, August 1, 2011 1:11 PM
  • Ok, I was doing the connection in the wrong way.

    First of all I was using WsHttpBinding when it was not needed, so now I use BasicHttpBinding (as ceej_3GuysonSharePoint said).

    Then I have to provide the ClientCredentials and finally set the ServerCertificateValidationCallback to return allways true.

    Now is running ok! This is the connection I have:

    CustomWebServiceClient proxy = new CustomWebServiceClient("BasicHttpBinding_ICustomWebService");
    
    proxy.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "passwordString", "domainName");
            proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            
    ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return (true); };
    
    Selector(proxy);
    


    Even though I'll mark your answers as correct.

    Thank you for the help!

    • Marked as answer by Marc Jordana Thursday, August 8, 2013 12:01 PM
    Monday, August 1, 2011 3:19 PM