Information mit schicken

  • C#
  • .NET (FX) 4.0

Es gibt 12 Antworten in diesem Thema. Der letzte Beitrag () ist von Thunderbolt.

    Information mit schicken

    Hallo,

    wenn ich über WCF vom Client den Server aufrufe um ne Methode zu starten wie kann ich da zusätzlich noch ne Information (einen String) mit schicken?

    das ist der "Anruf" beim Server...in der If-Schleife wird die Information vom Server dann wieder ausgegeben...und bei "BeginStart" würde ich gerne noch einen String mit zum Server schicken, damit dieser damit was macht

    C#-Quellcode

    1. string rmAddres = null;
    2. rmAddres = "net.tcp://" + IpAddress + ":" + PortNumber + "/IvertragAsynchron";
    3. // rmAddres = "net.tcp://" + "10.202.4.128" + ":" + "2121" + "/IvertragAsynchron";
    4. NetTcpBinding nettcpbinding = new NetTcpBinding(SecurityMode.None); // new NetTcpBinding(hier MUSS was stehen!! sonst tuts ned)
    5. ChannelFactory<IvertragAsynchron> chFactory = new ChannelFactory<IvertragAsynchron>(nettcpbinding);
    6. nettcpbinding.MaxReceivedMessageSize = 10485760; // 10485760 entspricht 10 MB
    7. TimeSpan mSpan = default(TimeSpan);
    8. mSpan = new TimeSpan(1200000000); // entspricht 2 Minuten (1 Millisekunde = 10.000 Ticks) -> 2min = 120.000ms = 1.200.000.000Ticks
    9. nettcpbinding.SendTimeout = mSpan;
    10. EndpointAddress epAddress = new EndpointAddress(rmAddres);
    11. objProxy = chFactory.CreateChannel(epAddress);
    12. this.StringContent = "Anfrage läuft...währenddessen kann das Fenster frei bewegt werden";
    13. if (objProxy.Ping())
    14. {
    15. objProxy.BeginStart(asyncResult =>
    16. {
    17. this.StringContent = objProxy.EndStart(asyncResult).Content;
    18. }, null);
    19. }

    Runshak schrieb:

    If-Schleife
    if-schleife.de/

    Zu Zeile 10: Warum verwendest du nicht TimeSpan.FromMinutes?

    Zum Problem: Schau mal, was BeginStart da für einen Parameter anbietet. Du setzt hier null. Ist es das, was du suchst?
    Mit freundlichen Grüßen,
    Thunderbolt
    Zum Problem: Schau mal, was BeginStart da für einen Parameter anbietet. Du setzt hier null. Ist es das, was du suchst?​


    das sieht gut aus...aber wie greif ich dann auf der Serverseite darauf zu?
    vertrag:

    Spoiler anzeigen

    C#-Quellcode

    1. ​namespace Vertrag
    2. {
    3. [ServiceContract(Name = "Grapefruit")] //muss den selben Namen haben wie IVertrag
    4. public interface IvertragAsynchron
    5. {
    6. [OperationContract(AsyncPattern = true)]
    7. IAsyncResult BeginStart(AsyncCallback callback, object asyncState);
    8. CdatenVertrag EndStart(IAsyncResult result);
    9. [OperationContract(AsyncPattern = true)]
    10. IAsyncResult BeginStop(AsyncCallback callback, object asyncState);
    11. CdatenVertrag EndStop(IAsyncResult result);
    12. [OperationContract(AsyncPattern = false)]
    13. bool Ping();
    14. }
    15. }


    aufruf im server

    Spoiler anzeigen

    C#-Quellcode

    1. public CdatenVertrag Start() //Antwort vom Server an den Client
    2. {
    3. string ergebnis = DLLCallerStart.Call();
    4. return new CdatenVertrag
    5. {
    6. Content = ergebnis //"Daten vom Server!"
    7. };
    8. }


    callmethode

    Spoiler anzeigen

    C#-Quellcode

    1. ​namespace Server
    2. {
    3. public static class DLLCallerStart //Startet Skala (führt Aktion aus, die vom Client gestartet wurde)
    4. {
    5. [DllImport("CallSkalaFkt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    6. private static extern Int32 CallSkalaFkt_SkalaStart(Int32 _hWnd, string _DB_Path, string _GLOB_GUID, string _RG_PATH, Int32 _EE_ID, Int32 _EE_Par, Int32 new_Ring, Int32 _auto_Start, ref Int32 Status_Flag);
    7. public static string Call()
    8. {
    9. System.Threading.Thread.Sleep(1000);
    10. string _DB_Path = "D:\\Projekte\\Skala_Simu\\Simu\\Glob_Simu.mdb";
    11. string _GLOB_GUID = "{guid{5ACB1481-2692-4C66-8BBC-9CC8B9FDF0C2}}";
    12. string _RG_PATH = "D:\\Projekte\\Skala_Simu\\Simu\\";
    13. Int32 _hWnd = 0;
    14. Int32 _EE_ID = 1;
    15. Int32 _EE_Par = 0;
    16. Int32 new_Ring = 1;
    17. Int32 _auto_Start = 0;
    18. Int32 Status_Flag = 0;
    19. GCHandle m_gch = GCHandle.Alloc(Status_Flag, GCHandleType.Pinned);
    20. try
    21. {
    22. int tmp = CallSkalaFkt_SkalaStart(_hWnd, _DB_Path, _GLOB_GUID, _RG_PATH, _EE_ID, _EE_Par, new_Ring, _auto_Start, ref Status_Flag);
    23. m_gch.Free();
    24. return tmp.ToString();
    25. }
    26. catch (Exception ex)
    27. {
    28. return ex.Message;
    29. }
    30. }
    31. }
    32. }
    hm dann bekomm ich nen Fehler im Client...

    C#-Quellcode

    1. ​if (objProxy.Ping())
    2. {
    3. objProxy.BeginStart(asyncResult =>
    4. {
    5. this.StringContent = objProxy.EndStart(asyncResult).Content;
    6. }, PfadContent); // Mitgabe von Informationen (hier aus der TxtBxPath)
    7. }
    Bilder
    • Fehler.png

      9,34 kB, 664×161, 140 mal angesehen