Respondida WCF Exception

  • sábado, 31 de marzo de 2012 7:28
     
      Tiene código

    Hallo,

    ich habe nach dem WCF-Tutorial hier eine WCF-Anwendung erstellt. Diese funktioniert auch einwandfrei. Nun habe ich die Anwendung um eine weitere Funktion erweitert, die Anwendungen auf dem Server starten soll.

    Servercode:

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    
    namespace Microsoft.ServiceModel.Samples
    {
        [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
        public interface ICalculator
        {
            [OperationContract]
            double Add(double n1, double n2);
            [OperationContract]
            double Subtract(double n1, double n2);
            [OperationContract]
            double Multiply(double n1, double n2);
            [OperationContract]
            double Divide(double n1, double n2);
            [OperationContract]
            void System(string command);
        }
    
        public class CalculatorService : ICalculator
        {
            public double Add(double n1, double n2)
            {
                double result = n1 + n2;
                Console.WriteLine("Received Add({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }
    
            public double Subtract(double n1, double n2)
            {
                double result = n1 - n2;
                Console.WriteLine("Received Subtract({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }
    
            public double Multiply(double n1, double n2)
            {
                double result = n1 * n2;
                Console.WriteLine("Received Multiply({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }
    
            public double Divide(double n1, double n2)
            {
                double result = n1 / n2;
                Console.WriteLine("Received Divide({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }
    
            public void System(string command)
            {
                Process.Start(command);
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");
                ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
    
                try
                {
                    selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
                    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                    smb.HttpGetEnabled = true;
                    selfHost.Description.Behaviors.Add(smb);
    
                    selfHost.Open();
    
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.WriteLine();
                    Console.ReadLine();
    
                    selfHost.Close();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("An Exception occured: {0}", ce.Message);
                    selfHost.Abort();
                }
            }
        }
    }

    Clientcode:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    
    namespace Client
    {
        class Program
        {
            static void Main(string[] args)
            {
                CalculatorClient test = new CalculatorClient();
                Console.WriteLine("Menüpunkt wählen");
                Console.WriteLine("1. Befehl ausführen");
                Console.WriteLine("2. Berechnung durchführen");
                int choice = Convert.ToInt32(Console.ReadLine());
    
                switch (choice)
                {
                    case 1:
                        test.System(Console.ReadLine());
                        break;
                    case 2:
                        int n1 = Convert.ToInt32(Console.ReadLine());
                        int n2 = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine(n1 + " + " + n2 + " = " + test.Add(n1, n2));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    

    Die Berechnungen funktionieren immernoch einwandfrei. Wenn ich jetzt aber einen Befehl ausführen will, indem ich z.B. erst "1" und dann "dir" eingebe, bekomme ich im Cient folgende Exception:

    Unbehandelte Ausnahme: System.ServiceModel.FaultException: Der Server konnte die
    Anforderung aufgrund eines internen Fehler nicht verarbeiten. Wenn Sie weitere
    Informationen zum Fehler erhalten möchten, aktivieren Sie entweder IncludeExcept
    ionDetailInFaults (entweder über das ServiceBehaviorAttribute oder das <serviceD
    ebug>-Konfigurationsverhalten) für den Client, um die Ausnahmeinformationen zurü
    ck an den Server zu senden, oder aktivieren Sie die Ablaufverfolgung gemäß der M
    icrosoft .NET Framework 3.0 SDK-Dokumentation, und prüfen Sie die Serverablaufve
    rfolgungsprotokolle.

    Server stack trace:
    bei System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Messag
    e reply, MessageFault fault, String action, MessageVersion version, FaultConvert
    er faultConverter)
    bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRun
    time operation, ProxyRpc& rpc)
    bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean o
    neway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan ti
    meout)
    bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCal
    lMessage methodCall, ProxyOperationRuntime operation)
    bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)


    Exception rethrown at [0]:
    bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage re
    qMsg, IMessage retMsg)
    bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgD
    ata, Int32 type)
    bei ICalculator.System(String command)
    bei CalculatorClient.System(String command) in C:\Users\Ich\documents\visual
    studio 2010\Projects\Service\Client\generatedProxy.cs:Zeile 90.
    bei Client.Program.Main(String[] args) in C:\Users\Ich\documents\visual studi
    o 2010\Projects\Service\Client\Program.cs:Zeile 22.

Todas las respuestas