I'm a professional developer, but I'm fairly new to WCF. I've been beating my head against the wall with this for some time, Google turned up nothing, and I'm hoping you guys will be able to help. I thought I had a WCF project working and now I don't - and no way to revert my code back to a working state. I can even create a small sample project to demonstrate the (bad) behavior. I've had this problem in both VS2010 RC and now RTM.
My solution has three projects: a contracts class library, a server console app, and a client console app.
My contracts look like this:
Server console app:Code:namespace WcfTest.Services { [DataContract] public class TestData { public string Value { get; set; } } [ServiceContract] public interface ITestService { [OperationContract] TestData DoSomeWork(); } }
Client console app:Code:<service name="WcfTest.Services.TestService"> <endpoint address="http://localhost:8002/WcfTest/Services/Test" binding="wsHttpBinding" contract="WcfTest.Services.ITestService" /> </service> static void Main(string[] args) { ServiceHost serviceHost = new ServiceHost(typeof(TestService)); serviceHost.Open(); Console.ReadKey(); serviceHost.Close(); }
When I run the server and client apps (in that order) they both run without throwing any exceptions, but the only thing that shows on the client output is a blank line. I've also set a breakpoint and looked at the return value from the service. The variable value has a valid instance of the class TestData, but the Value property is null. I've read that this can happen if your data contracts on the client and server sides are in different namespaces, but since I'm reusing the contract via referencing a 3rd assembly I don't see how that's possible. Any ideas? Thanks for your help.Code:<client> <endpoint name="Test" address="http://localhost:8002/WcfTest/Services/Test" binding="wsHttpBinding" contract="WcfTest.Services.ITestService"> </endpoint> </client> static void Main(string[] args) { ChannelFactory<ITestService> testServiceFactory = new ChannelFactory<ITestService>("Test"); testServiceFactory.Open(); ITestService testService = testServiceFactory.CreateChannel(); TestData value = testService.DoSomeWork(); Console.WriteLine(value.Value); testServiceFactory.Close(); Console.ReadKey(); }




Reply With Quote