Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# Service Problem mit Objektinstanz und Objektverweis

Empfohlene Antworten

Veröffentlicht

Hallo liebe community,

ich habe folgendes Problem. wenn ich folgenden Code ausführe kommt der Fehler "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt". Ich weiß nicht wie ich dieses Problem lösen kann.

Der Fehler tritt auf bei:

SVC.User user = new SVC.User();

                    user.UserName = loginTxtBoxUName.Text.ToString();
 private void Connect()

        {

            if (proxy == null)

            {

                try

                {

                    this.localClient = new SVC.Client();

                    SVC.User user = new SVC.User();

                    user.UserName = loginTxtBoxUName.Text.ToString();

                    this.localClient.User = user;

                    this.localClient.AvatarID = loginComboBoxImgs.SelectedIndex;

                    InstanceContext context = new InstanceContext(this);

                    proxy = new SVC.ChatClient(context);


                    //As the address in the configuration file is set to localhost

                    //we want to change it so we can call a service in internal 

                    //network, or over internet

                    string servicePath = proxy.Endpoint.ListenUri.AbsolutePath;

                    string serviceListenPort = proxy.Endpoint.Address.Uri.Port.ToString();


                    proxy.Endpoint.Address = new EndpointAddress("net.tcp://" + loginTxtBoxIP.Text.ToString() + ":" + serviceListenPort + servicePath);



                    proxy.Open();


                    proxy.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);

                    proxy.InnerDuplexChannel.Opened += new EventHandler(InnerDuplexChannel_Opened);

                    proxy.InnerDuplexChannel.Closed += new EventHandler(InnerDuplexChannel_Closed);

                    proxy.ConnectAsync(this.localClient);

                    proxy.ConnectCompleted += new EventHandler<ConnectCompletedEventArgs>(proxy_ConnectCompleted);

                }

                catch (Exception ex)

                {

                    loginTxtBoxUName.Text = ex.Message.ToString();

                    loginLabelStatus.Content = "Offline";

                    loginButtonConnect.IsEnabled = true;

                }

            }

            else

            {

                HandleProxy();

            }

        }
Meine Klassen im Hintergrund sehen wie folgt aus: (Client dem der User hinzugefügt werden soll UND der User selbst)
[System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]

    [System.Runtime.Serialization.DataContractAttribute(Name = "User", Namespace = "http://schemas.datacontract.org/2004/07/ServiceAssembly")]

    [System.SerializableAttribute()]

    public partial class User : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged

    {


        [System.NonSerializedAttribute()]

        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private String UserNameField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private String PasswordField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private Person PersonField;


        [global::System.ComponentModel.BrowsableAttribute(false)]

        public System.Runtime.Serialization.ExtensionDataObject ExtensionData

        {

            get

            {

                return this.extensionDataField;

            }

            set

            {

                this.extensionDataField = value;

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public Person Person

        {

            get

            {

                return this.PersonField;

            }

            set

            {

                if ((this.PersonField.Equals(value) != true))

                {

                    this.PersonField = value;

                    this.RaisePropertyChanged("Person");

                }

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public String UserName

        {

            get

            {

                return this.UserNameField;

            }

            set

            {

                if ((this.UserNameField.Equals(value) != true))

                {

                    this.UserNameField = value;

                    this.RaisePropertyChanged("UserName");

                }

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public String Password

        {

            get

            {

                return this.PasswordField;

            }

            set

            {

                if ((this.PasswordField.Equals(value) != true))

                {

                    this.PasswordField = value;

                    this.RaisePropertyChanged("Password");

                }

            }

        }


        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;


        protected void RaisePropertyChanged(string propertyName)

        {

            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;

            if ((propertyChanged != null))

            {

                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));

            }

        }

    }


    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]

    [System.Runtime.Serialization.DataContractAttribute(Name="Client", Namespace="http://schemas.datacontract.org/2004/07/ServiceAssembly")]

    [System.SerializableAttribute()]

    public partial class Client : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged 

    {


        [System.NonSerializedAttribute()]

        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private int AvatarIDField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private string NameField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private SVC.User UserField;


        [System.Runtime.Serialization.OptionalFieldAttribute()]

        private System.DateTime TimeField;


        [global::System.ComponentModel.BrowsableAttribute(false)]

        public System.Runtime.Serialization.ExtensionDataObject ExtensionData {

            get {

                return this.extensionDataField;

            }

            set {

                this.extensionDataField = value;

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public SVC.User User

        {

            get

            {

                return this.UserField;

            }

            set

            {

                if ((this.UserField.Equals(value) != true))

                {

                    this.UserField = value;

                    this.RaisePropertyChanged("User");

                }

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public int AvatarID {

            get {

                return this.AvatarIDField;

            }

            set {

                if ((this.AvatarIDField.Equals(value) != true)) {

                    this.AvatarIDField = value;

                    this.RaisePropertyChanged("AvatarID");

                }

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public string Name

        {

            get

            {

                return this.NameField;

            }

            set

            {

                if ((object.ReferenceEquals(this.NameField, value) != true))

                {

                    this.NameField = value;

                    this.RaisePropertyChanged("Name");

                }

            }

        }


        [System.Runtime.Serialization.DataMemberAttribute()]

        public System.DateTime Time {

            get {

                return this.TimeField;

            }

            set {

                if ((this.TimeField.Equals(value) != true)) {

                    this.TimeField = value;

                    this.RaisePropertyChanged("Time");

                }

            }

        }


        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;


        protected void RaisePropertyChanged(string propertyName) {

            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;

            if ((propertyChanged != null)) {

                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));

            }

        }

    }

Über Hilfe freue ich mich sehr :)

Greetz Shiggy

  • Autor

private void buttonConnect_Click(object sender, RoutedEventArgs e)

        {

            loginButtonConnect.IsEnabled = false;

            loginLabelStatus.Content = "Connecting..";

            proxy = null;

            Connect();


        }

Hier innerhalb des Clickereignisses wird die Connect-Methode aufgerufen. Sobald man also auf den knopf drückt soll sich der client mit dem service verbinden. dabei soll er die informationen aus dem eingabefeld übernehmen und später sobald ich soweit bin dann in der datenbank nachschaun ob denn der nutzer schon existiert. die ganze zeit hat es auch ohne db funktioniert weil ich das nur auf die namen abgefragt habe.

seit ich aber den User in den Client mit eingehängt habe funktioniert das ganze nichtmehr da er probleme hat die instanz des Users dem Client hinzuzufügen.

Bearbeitet von Shiggy

  • Autor

Hura,

ich habe mein Problem entdeckt.

das Problem war dass er an dieser Stelle


[System.Runtime.Serialization.DataMemberAttribute()]

        public SVC.User User

        {

            get

            {

                return this.UserField;

            }

            set

            {

                if ((this.UserField.Equals(value) != true))

                {

                    this.UserField = value;

                    this.RaisePropertyChanged("User");

                }

            }

        }

ein problem hatte im setter zu überprüfen ob der aktuelle User im Client null ist.

nachdem ich dies auskommentiert hatte hat es funktioniert.

:)

Greetz Shiggy

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.