Search code examples
c#.nethttpswsdlcardspace

CardSpaceException: No version of the CardSpace service was found to be installed on the machine


first of all, I don't have clue, what am I doing. I'm a Java dev and I have to fix a C# program somebody else wrote.

We had to update and move a web services to another machine. The update included a change to https. The tool I have to fix is used to upload files to the web service and is running on the same machine as the service. The communication is over SOAP (I think) using a wsdl file. The SSL-certificate is self signed but stored in the trusted cert storage.

First I tried to just change the paths to the new server but the upload tool complained about the change to https. Unfortunately, I don't have the exception anymore.

Then I re-imported the new wsdl and now I'm getting:

System.IdentityModel.Selectors.CardSpaceException: No version of the CardSpace service was found to be installed on the machine. Please install CardSpace and retry the operation.

Server stack trace: at System.IdentityModel.Selectors.CardSpaceShim.GetCardSpaceImplementationDll() at System.IdentityModel.Selectors.CardSpaceShim.InitializeIfNecessary()
at System.IdentityModel.Selectors.CardSpaceSelector.GetToken(CardSpacePolicyElement[] policyChain, SecurityTokenSerializer tokenSerializer) at System.ServiceModel.Description.ClientCredentials.GetInfoCardSecurityToken(Boolean requiresInfoCard, CardSpacePolicyElement[] chain, SecurityTokenSerializer tokenSerializer) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]: at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.DisplayInitializationUI() at System.ServiceModel.Channels.ServiceChannel.CallDisplayUIOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) at System.ServiceModel.Channels.ServiceChannel.EnsureDisplayUI() 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 [1]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at CLIIkarosImport.ImportUploadService.IImportUploadService.UploadFile(FileUploadMessage request) at CLIIkarosImport.ImportUploadService.ImportUploadServiceClient.CLIIkarosImport.ImportUploadService.IImportUploadService.UploadFile(FileUploadMessage request) in C:\projekte_c#\CLIIkarosImport\CLIIkarosImport\Service References\ImportUploadService\Reference.cs:line 194 at CLIIkarosImport.ImportUploadService.ImportUploadServiceClient.UploadFile(Int64 FileSize, String OriginalFileName, String UserIpV4, String UserIpV6, String UserName, Stream FileStream, String& FileId, String& Message) in C:\projekte_c#\CLIIkarosImport\CLIIkarosImport\Service References\ImportUploadService\Reference.cs:line 205 at CLIIkarosImport.Webservice.Import.ImportServiceModule.<>c__DisplayClass0_0.<.ctor>b__2(Object x) in C:\projekte_c#\CLIIkarosImport\CLIIkarosImport\Webservice\Import\ImportServiceModule.cs:line 86

         Get["/ImportFromPublicLocation/{path}"] = x =>
         {
                string newPath = x.path;
                newPath = newPath.Replace("-*-", ".");
                newPath = newPath.Replace("-#-", @"\");

                var path = Uri.UnescapeDataString(newPath);    
                Console.WriteLine($"Given path is {path}");

                if (!File.Exists(path))
                {
                    Console.WriteLine("File doesn't exist!");
                    return new Response() {StatusCode = HttpStatusCode.NoContent};
                }

                var response = new CustomResponse();

                using (var client = new ImportUploadServiceClient())
                {
                    var fileName = Path.GetFileName(path);
                    var fStream = new FileStream(path, FileMode.Open);

                    string id, message;
                    ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
                    try
                    {
                        var fResponse = client.UploadFile(fStream.Length, fileName, "", "", "Import", fStream, out id, out message);
                        Console.WriteLine($"Response is {fResponse}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                    
                    response.JobId = id;
                    response.Message = message;
                }

                return new JsonResponse<CustomResponse>(response, defaultJsonSerializer);
            };

I don't know if the change to https is the issue, or the move to the new server. I don't know if my predecessor did any changes to the old machine to make it work.

Let me know, if you need any further information.

EDIT: I think its an issue within the application itself. I get the same Exception if the webserver is shut down and I can't find any calls to the api-server in wireshark


Solution

  • In the end it was a security issue in user authentication with STS (AD FS or FS-STS) and I had to use classes from a DLL provided by the service provider to connect to the service.