although I don’t know what your problem is, maybe something is wrong with your generation code Here is a complete working example for sending a string from a client and then receiving it from the server.
using System; using System.Runtime.Serialization; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; namespace MySpace { [DataContract] public class Data { [DataMember] public string MyString; } [ServiceContract] public interface IService { [OperationContract] Data Method(Data dd); } public class Service : IService { public Data Method(Data dd) { dd.MyString = dd.MyString + " String from Server."; return dd; } } class Program { static void Main(string[] args) { string Url = "http://localhost:8000/"; Binding binding = new BasicHttpBinding(); ServiceHost host = new ServiceHost(typeof(Service)); host.AddServiceEndpoint(typeof(IService), binding, Url); host.Open(); ChannelFactory<IService> fac = new ChannelFactory<IService>(binding); fac.Open(); IService proxy = fac.CreateChannel(new EndpointAddress(Url)); Data d = new Data(); d.MyString = "String from client."; d = proxy.Method(d); fac.Close(); host.Close(); Console.WriteLine("Result after calling \n " + d.MyString); Console.ReadLine(); } } }
Update: running code without DataContract, just passing the string, it works fab
using System; using System.Runtime.Serialization; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; namespace MySpace { [ServiceContract] public interface IService { [OperationContract] string Method(string dd); } public class Service : IService { public string Method(string dd) { dd =dd+ " String from Server."; return dd; } } class Program { static void Main(string[] args) { string Url = "http://localhost:8000/"; Binding binding = new BasicHttpBinding(); ServiceHost host = new ServiceHost(typeof(Service)); host.AddServiceEndpoint(typeof(IService), binding, Url); host.Open(); ChannelFactory<IService> fac = new ChannelFactory<IService>(binding); fac.Open(); IService proxy = fac.CreateChannel(new EndpointAddress(Url)); string d = proxy.Method("String from client."); fac.Close(); host.Close(); Console.WriteLine("Result after calling \n " + d); Console.ReadLine(); } } }
Update 3 I still think that something is wrong with your generated code / proxy as here, this is a test with different interfaces on the client / server (any way to ignore it if your problem has already been resolved :)
using System; using System.Runtime.Serialization; using System.IO; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; namespace MyClient { [ServiceContract] public interface IService { [OperationContract] string Method(string dd); } } namespace MyServer { [ServiceContract] public interface IService { [OperationContract] string Method(string dd); } } namespace MySpace { public class Service :MyServer.IService { public string Method(string dd) { dd =dd+ " String from Server."; return dd; } } class Program { static void Main(string[] args) { string Url = "http://localhost:8000/"; Binding binding = new BasicHttpBinding(); ServiceHost host = new ServiceHost(typeof(Service)); host.AddServiceEndpoint(typeof(MyServer.IService), binding, Url); host.AddDefaultEndpoints(); host.Open(); ChannelFactory<MyClient.IService> fac = new ChannelFactory<MyClient.IService>(binding); fac.Open(); MyClient.IService proxy = fac.CreateChannel(new EndpointAddress(Url)); string d = proxy.Method("String from client."); fac.Close(); host.Close(); Console.WriteLine("Result after calling \n " + d); Console.ReadLine(); Console.ReadLine(); } } }
source share