c# - Return my object from WCF service. -


I have an application that hosts WCF service and I want to return this class object : Namespace classes [[DataContract] Public class network adapter {[Database] Public string name {get; Set; } [Datamember] get public string id { Set; } [Datamember] public string description {get; Set; } [Database] Public String IPadress {Receive; Set; } [Datamember] Private string gateway ip address; [Datamember] public string speed {get; Set; } [Database] Public String NetworkInterfaceType {get; Set; } [Datamember] public string macAddress {get; Set; } [DataMember] LivePacketDevice LivePacketDevice; [Database] Public PacketDevice PacketDive {Receive livePacketDevice; }} Public Network Adapter (LivePacket Devices Packet Device) {livePacketDevice = packetDevice; } Public override string toasting () {Return details; } Public Static Network Adapters [] getAll () {List & lt; Network adapter & gt; List = new list & lt; NetworkAdapter & gt; (); Agarwal (Network Interface Adapter In Network Interface. Gate Lynnetwork Interface ()) Agragad (Unicestip Adapter adapter in Adit.GettyProperties (). Unicast Address (if (System.Net. IP Adapter. ISOLock (UNIST. Address) & amp; Unistest Address: Address Family! = Address Family.InterNetworkV6) {StringBuilder Gateway IP Address = New StringBuilder (); String Gateway IP address display = string; empty; foreign (ed adau Various addresses in the Garter.GETIPProperties (Gateway addressers) {gateway ipdressers.append address) gateway ipdidars.append ("");} if (gateway ipdressers langs gt; 0) {gateway ipdressersdisplay = gateway ipdedors.tostring (). Trimand ('');} if (list.Any (L = & gt; L.ID == adapter.Id)) {list.Add (New NetworkAdapter (getDevice (adapter.Id)) {name = adapter.Name , Id = adapter.Id, Description = adapter.Description, IPAddress = uniCast.Address.ToString (), NetworkInterfaceType = adapter.NetworkInterfaceType.ToString (), speed = adapter.Speed.ToString ("#, ## 0"), MacAddress = getMacAddress (adapter. GetPhysicalAddress () .ostring ()), gatewayipendsress = gatewayipedadressreserve}}; }}} // return list. GroupB (n = & gt; n.id). Select (g = & gt; g.firster default ()). ToArray (); Return list Tore (); } Private Stable LivePacketDevice getDevice (String ID) {LivePacketDevice Return. AllLocalMachine.First (x = & x; x.Name.Contains (id)); } Private static string getMacAddress (string old MAC) {int count = 0; String newMAC = old MAC; For (Int i = 2; i & lt; Old MAC lamb; I + = 2) {NMAC = New Mac. Insert (I + calculation ++, ":"); } New MAC return; } Get the public string default gateway {if (gateway ip address! = "") {Return gateway ipdater;} return "n / a";}} private static string getIpFourthSegment {string} IP address {try {string [] arr = ipAddress.Split Return] [3];} hold (exception) {return null;}}}}

this is my service:

  [ServiceContract] Public Interface IService1 {[OperationContract] NetworkAdapter [] GetAdapters (); [Operation Contract] String GetDate ();} [ServiceBehavior (ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSe Ssion) Public class Service1: IService1 {Public NetworkAdapter [GetAdapters () {IEnumerable & lt; NetworkAdapter & gt; Adapter = NetworkAdapter.getAll (); Return Adapter .ORA ();} Public String GetDate () {DateTime.Now .ToString ();}}   

When I try to run the GetAdapters function, this error gets:

  An unhandled exception of type 'System ServiceModel.CommunicationException' Additional information in mscorlib.dll: The socket connection was aborted. This may be due to an error processing your message or a remote host, or an underlying network resource problem can be obtained more than that. The local socket timeout was '00: 00: 59.9599960 '  

This code works fine when trying to run the GetDate and returns a simple string That I have to configure my class in another way? I've added [DataMember] to each member

LivePacketDevice and PacketDevice are required to be [DataContract] s, even if it is only [Serializable] , even if working Otherwise the WCF does not know how to transfer them to the customer.

In addition to this, it is advisable to move objects only, which capture data, not functionality, as the functionality will not be available to the customer. The stub created on the client side will have only data fields, not methods, because the code is not transferred / cloned.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -