![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | ChannelFactory with NetTCP Binding problem I think I may be making things more complicated than I need to, but i'm really stuck here. I'm trying to create a host, and connect to it NetTCP. Right now I'm trying to do both operations from within a single process, but am not having any luck at all. I've got an Interface & Implementation: [ServiceContract()] public interface IDoSomething { [OperationContract()] int Add(int x, int y); } public class DoSomething : IDoSomething { public int Add(int x, int y) { return x + y; } } ... a member variable & a well known URL: ServiceHost _host; string _uri = @"net.tcp://127.0.0.1:9999/test"; Now, I'm create a host: NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); _host = new ServiceHost(typeof(DoSomething)); _host.AddServiceEndpoint(typeof(IDoSomething), binding, _uri); _host.Open(); When that's done, I create a Channel, and try to call the service: NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None); EndpointAddress myEndpoint = new EndpointAddress(_uri); IDoSomething client = ChannelFactory<IDoSomething>.CreateChannel(tcpBinding, myEndpoint); int z = client.Add(100, 200); This just refuses to work - it does when Add() is called. Sometimes I get a timeout (after 1 minute), other times I get a "socket forcebly closed by remote host" issue. All the WCF samples that use the various Web Service bindings work just fine. I've got Windows Firewall all, I can see the listener IP & port showing up in the list from NetStat, and things seem correct. I've run WCF Trace, but to no avail.The exceptions that I see aren't of any use at all. -- Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins |
My System Specs![]() |
| | #2 (permalink) |
| | Re: ChannelFactory with NetTCP Binding problem The problem seems to be related to hosting the service & the dynamically created client proxy in the same process. If I host them in different processes, everything works well. Ah well. That just makes it a bit more difficult to test.... -- Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins "Chris Mullins [MVP]" <cmullins@yahoo.com> wrote in message news:ea1hEEuVHHA.392@TK2MSFTNGP06.phx.gbl... >I think I may be making things more complicated than I need to, but i'm >really stuck here. I'm trying to create a host, and connect to it NetTCP. >Right now I'm trying to do both operations from within a single process, >but am not having any luck at all. > > I've got an Interface & Implementation: > [ServiceContract()] > public interface IDoSomething > { > [OperationContract()] > int Add(int x, int y); > } > > public class DoSomething : IDoSomething > { > public int Add(int x, int y) { return x + y; } > } > > .. a member variable & a well known URL: > ServiceHost _host; > string _uri = @"net.tcp://127.0.0.1:9999/test"; > > Now, I'm create a host: > NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); > _host = new ServiceHost(typeof(DoSomething)); > _host.AddServiceEndpoint(typeof(IDoSomething), binding, _uri); > _host.Open(); > > When that's done, I create a Channel, and try to call the service: > > NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None); > EndpointAddress myEndpoint = new EndpointAddress(_uri); > > IDoSomething client = > ChannelFactory<IDoSomething>.CreateChannel(tcpBinding, myEndpoint); > int z = client.Add(100, 200); > > This just refuses to work - it does when Add() is called. Sometimes I get > a timeout (after 1 minute), other times I get a "socket forcebly closed by > remote host" issue. All the WCF samples that use the various Web Service > bindings work just fine. > > I've got Windows Firewall all, I can see the listener IP & port showing up > in the list from NetStat, and things seem correct. I've run WCF Trace, but > to no avail.The exceptions that I see aren't of any use at all. > > -- > Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP > http://www.coversant.com/blogs/cmullins > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: ChannelFactory with NetTCP Binding problem I have been working on same. Here is single console app that works here. Your error sounds like a type issue as I saw that before while testing various ways. hth FooService.cs ============================================================== using System; using System.Configuration; using System.ServiceModel; using System.Runtime.Serialization; namespace Wjs.FooService { // Define a service contract. [ServiceContract(Namespace = "http://Wjs.FooService")] public interface IMyService { [OperationContract] string GetName(); [OperationContract] Person GetPerson(); [OperationContract] bool SetPerson(Person person); } // WCF Service class which implements the service contract. public class MyService : IMyService { public string GetName() { return "JobService"; } public Person GetPerson() { return new Person(); } public bool SetPerson(Person p) { return true; } } [DataContract] public class Person { [DataMember] public string Name = "William"; } } Program.cs ================================================================================= using System; using System.Collections.Generic; using System.Text; using System.Configuration; using System.ServiceModel; namespace Wjs.FooService { /// <summary> /// Represents a minimal WCF self-hosted service using a console app. /// To Make client proxy: svcutil http://localhost:44001/MyService/ /// </summary> class Program { static void Main(string[] args) { // Create a ServiceHost for the CalculatorService type. using (ServiceHost serviceHost = new ServiceHost(typeof(MyService))) { // Open the ServiceHost to create listeners and start listening for messages. serviceHost.Open(); // The service can now be accessed. We can now also make blocking calls as service // will handle requests on seperate threads. Console.WriteLine("MyService is started."); DoClient(); Console.WriteLine("Press <ENTER> to terminate service."); Console.ReadLine(); } } static void DoClient() { NetTcpBinding tcpBinding = new NetTcpBinding(); EndpointAddress myEndpoint = new EndpointAddress("net.tcp://localhost:44002/MyService"); using (ChannelFactory<IMyService> tcpChannel = new ChannelFactory<IMyService>(tcpBinding, myEndpoint)) { IMyService js = tcpChannel.CreateChannel(); // Create proxy to service. Console.WriteLine(js.GetName()); Person p = js.GetPerson(); Console.WriteLine("Person: {0}", p.Name); bool result = js.SetPerson(p); Console.WriteLine("SetPerson result:{0}", result); } } } } App.Config (used by server side) ============================================================================= <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="Wjs.FooService.MyService" behaviorConfiguration="MEXGET"> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:44002/MyService"/> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" contract="Wjs.FooService.IMyService" /> <endpoint address="MEX" binding="mexTcpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MEXGET"> <serviceMetadata /> <serviceDebug includeExceptionDetailInFaults="True" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> -- William Stacey [C# MVP] PCR concurrency library: www.codeplex.com/pcr PSH Scripts Project www.codeplex.com/psobject |
My System Specs![]() |
| | #4 (permalink) |
| | Re: ChannelFactory with NetTCP Binding problem I'm not really clear on the difference between your code & mine. I was trying to do everything in code, with no config file at all. Looking at your config, the difference seems to be that you've got a Metadata Exchange endpoint enabled, whereas I don't. The trouble for me is that my code works great if I split it into two processes - a client & a server. I can have any number of clients all hitting the server as well, and things are happy. It's *only* the single-process case that's causing me troubles. I'll give it a shot using the MEX endpoint... -- Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP http://www.coversant.com/blogs/cmullins "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message news:uN9iNpwVHHA.4720@TK2MSFTNGP04.phx.gbl... >I have been working on same. Here is single console app that works here. > Your error sounds like a type issue as I saw that before while testing > various ways. hth > > FooService.cs > ============================================================== > using System; > using System.Configuration; > using System.ServiceModel; > using System.Runtime.Serialization; > > namespace Wjs.FooService > { > // Define a service contract. > [ServiceContract(Namespace = "http://Wjs.FooService")] > public interface IMyService > { > [OperationContract] > string GetName(); > [OperationContract] > Person GetPerson(); > [OperationContract] > bool SetPerson(Person person); > } > > // WCF Service class which implements the service contract. > public class MyService : IMyService > { > public string GetName() > { > return "JobService"; > } > public Person GetPerson() > { > return new Person(); > } > public bool SetPerson(Person p) > { > return true; > } > } > > [DataContract] > public class Person > { > [DataMember] > public string Name = "William"; > } > } > > Program.cs > ================================================================================= > using System; > using System.Collections.Generic; > using System.Text; > using System.Configuration; > using System.ServiceModel; > > namespace Wjs.FooService > { > /// <summary> > /// Represents a minimal WCF self-hosted service using a console app. > /// To Make client proxy: svcutil http://localhost:44001/MyService/ > /// </summary> > class Program > { > static void Main(string[] args) > { > // Create a ServiceHost for the CalculatorService type. > using (ServiceHost serviceHost = new > ServiceHost(typeof(MyService))) > { > // Open the ServiceHost to create listeners and start > listening for messages. > serviceHost.Open(); > > // The service can now be accessed. We can now also make > blocking calls as service > // will handle requests on seperate threads. > Console.WriteLine("MyService is started."); > > DoClient(); > > Console.WriteLine("Press <ENTER> to terminate service."); > Console.ReadLine(); > } > } > > static void DoClient() > { > NetTcpBinding tcpBinding = new NetTcpBinding(); > EndpointAddress myEndpoint = new > EndpointAddress("net.tcp://localhost:44002/MyService"); > using (ChannelFactory<IMyService> tcpChannel = new > ChannelFactory<IMyService>(tcpBinding, myEndpoint)) > { > IMyService js = tcpChannel.CreateChannel(); // Create > proxy to service. > Console.WriteLine(js.GetName()); > Person p = js.GetPerson(); > Console.WriteLine("Person: {0}", p.Name); > bool result = js.SetPerson(p); > Console.WriteLine("SetPerson result:{0}", result); > } > } > } > } > > App.Config (used by server side) > ============================================================================= > <?xml version="1.0" encoding="utf-8" ?> > <configuration> > <system.serviceModel> > <services> > <service name="Wjs.FooService.MyService" > behaviorConfiguration="MEXGET"> > <host> > <baseAddresses> > <add baseAddress="net.tcp://localhost:44002/MyService"/> > </baseAddresses> > </host> > <endpoint address="" > binding="netTcpBinding" > contract="Wjs.FooService.IMyService" /> > <endpoint address="MEX" > binding="mexTcpBinding" > contract="IMetadataExchange" /> > </service> > </services> > <behaviors> > <serviceBehaviors> > <behavior name="MEXGET"> > <serviceMetadata /> > <serviceDebug includeExceptionDetailInFaults="True" /> > </behavior> > </serviceBehaviors> > </behaviors> > </system.serviceModel> > </configuration> > > > -- > William Stacey [C# MVP] > PCR concurrency library: www.codeplex.com/pcr > PSH Scripts Project www.codeplex.com/psobject > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: ChannelFactory with NetTCP Binding problem Hmm. AFAICT, the mex should not be needed at this point as we are not using it here. I can take a look if you want to zip up and post your single process solution that shows the error. I know these things can drive you crazy until you find it. -- William Stacey [C# MVP] PCR concurrency library: www.codeplex.com/pcr PSH Scripts Project www.codeplex.com/psobject "Chris Mullins [MVP]" <cmullins@yahoo.com> wrote in message news:OTLtcs3VHHA.5060@TK2MSFTNGP06.phx.gbl... | I'm not really clear on the difference between your code & mine. | | I was trying to do everything in code, with no config file at all. Looking | at your config, the difference seems to be that you've got a Metadata | Exchange endpoint enabled, whereas I don't. | | The trouble for me is that my code works great if I split it into two | processes - a client & a server. I can have any number of clients all | hitting the server as well, and things are happy. It's *only* the | single-process case that's causing me troubles. | | I'll give it a shot using the MEX endpoint... | | -- | Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP | http://www.coversant.com/blogs/cmullins | | "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message | news:uN9iNpwVHHA.4720@TK2MSFTNGP04.phx.gbl... | >I have been working on same. Here is single console app that works here. | > Your error sounds like a type issue as I saw that before while testing | > various ways. hth | > | > FooService.cs | > ============================================================== | > using System; | > using System.Configuration; | > using System.ServiceModel; | > using System.Runtime.Serialization; | > | > namespace Wjs.FooService | > { | > // Define a service contract. | > [ServiceContract(Namespace = "http://Wjs.FooService")] | > public interface IMyService | > { | > [OperationContract] | > string GetName(); | > [OperationContract] | > Person GetPerson(); | > [OperationContract] | > bool SetPerson(Person person); | > } | > | > // WCF Service class which implements the service contract. | > public class MyService : IMyService | > { | > public string GetName() | > { | > return "JobService"; | > } | > public Person GetPerson() | > { | > return new Person(); | > } | > public bool SetPerson(Person p) | > { | > return true; | > } | > } | > | > [DataContract] | > public class Person | > { | > [DataMember] | > public string Name = "William"; | > } | > } | > | > Program.cs | > ================================================================================= | > using System; | > using System.Collections.Generic; | > using System.Text; | > using System.Configuration; | > using System.ServiceModel; | > | > namespace Wjs.FooService | > { | > /// <summary> | > /// Represents a minimal WCF self-hosted service using a console app. | > /// To Make client proxy: svcutil http://localhost:44001/MyService/ | > /// </summary> | > class Program | > { | > static void Main(string[] args) | > { | > // Create a ServiceHost for the CalculatorService type. | > using (ServiceHost serviceHost = new | > ServiceHost(typeof(MyService))) | > { | > // Open the ServiceHost to create listeners and start | > listening for messages. | > serviceHost.Open(); | > | > // The service can now be accessed. We can now also make | > blocking calls as service | > // will handle requests on seperate threads. | > Console.WriteLine("MyService is started."); | > | > DoClient(); | > | > Console.WriteLine("Press <ENTER> to terminate service."); | > Console.ReadLine(); | > } | > } | > | > static void DoClient() | > { | > NetTcpBinding tcpBinding = new NetTcpBinding(); | > EndpointAddress myEndpoint = new | > EndpointAddress("net.tcp://localhost:44002/MyService"); | > using (ChannelFactory<IMyService> tcpChannel = new | > ChannelFactory<IMyService>(tcpBinding, myEndpoint)) | > { | > IMyService js = tcpChannel.CreateChannel(); // Create | > proxy to service. | > Console.WriteLine(js.GetName()); | > Person p = js.GetPerson(); | > Console.WriteLine("Person: {0}", p.Name); | > bool result = js.SetPerson(p); | > Console.WriteLine("SetPerson result:{0}", result); | > } | > } | > } | > } | > | > App.Config (used by server side) | > ============================================================================= | > <?xml version="1.0" encoding="utf-8" ?> | > <configuration> | > <system.serviceModel> | > <services> | > <service name="Wjs.FooService.MyService" | > behaviorConfiguration="MEXGET"> | > <host> | > <baseAddresses> | > <add baseAddress="net.tcp://localhost:44002/MyService"/> | > </baseAddresses> | > </host> | > <endpoint address="" | > binding="netTcpBinding" | > contract="Wjs.FooService.IMyService" /> | > <endpoint address="MEX" | > binding="mexTcpBinding" | > contract="IMetadataExchange" /> | > </service> | > </services> | > <behaviors> | > <serviceBehaviors> | > <behavior name="MEXGET"> | > <serviceMetadata /> | > <serviceDebug includeExceptionDetailInFaults="True" /> | > </behavior> | > </serviceBehaviors> | > </behaviors> | > </system.serviceModel> | > </configuration> | > | > | > -- | > William Stacey [C# MVP] | > PCR concurrency library: www.codeplex.com/pcr | > PSH Scripts Project www.codeplex.com/psobject | > | > | > | | |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Binding an ImageBrush Problem | .NET General | |||