[Mono-dev] WCF in Mono 2.6.7

joelcaner joelcaner at gmail.com
Fri Jan 14 09:37:26 EST 2011


I am having trouble getting WCF working on Mono in Suse Linux 11.3
I have the client as follow:
BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.None;
            binding.TransferMode = TransferMode.Streamed;
            binding.MessageEncoding = WSMessageEncoding.Mtom;
            binding.MaxReceivedMessageSize = int.MaxValue;

            EndpointAddress address = new
EndpointAddress("http://localhost:5800/DataUploader");
            ChannelFactory<IDataUploader> channel = new
ChannelFactory<IDataUploader>(binding, address);

            IDataUploader uploader = channel.CreateChannel();
            
            try
            {


                uploader.Upload(File.Open(@"G:\anthem-1.5.2.zip",
FileMode.Open, FileAccess.Read));
                Console.WriteLine("File uploaded to the server");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                ((IClientChannel)uploader).Close();
               

            }

I have the following interface:
[ServiceContract]
    interface IDataUploader
    {
        [OperationContract]
        void Upload(Stream data);
    }

Now the service is as follow on DataUploader.cs:
class DataUploader : IDataUploader

    {

        #region IDataUploader Members

        public void Upload(Stream data)

        {

            string xmlFile = @"c:\temp\uploadedfile" + ".zip";



            using (FileStream fs = new FileStream(xmlFile, FileMode.Create))

            {

                int bufferSize = 1 * 1024 * 1024; // 1MB buffer

                byte[] buffer = new byte[bufferSize];

                int bytes;



                while ((bytes = data.Read(buffer, 0, bufferSize)) > 0)

                {

                    fs.Write(buffer, 0, bytes);

                    fs.Flush();

                }

            }



           

        }

         #endregion



       

    }

Now on IDataUploader.cs:
[ServiceContract]

    interface IDataUploader

    {

        [OperationContract]

        void Upload(Stream data);

    }

On the main.cs I have:
public static void Main (string[] args)

		{

			ServiceHost host = new ServiceHost(typeof(DataUploader));



            BasicHttpBinding binding = new BasicHttpBinding();

			binding.Security.Mode = BasicHttpSecurityMode.None;

            binding.TransferMode = TransferMode.Streamed;

			binding.MessageEncoding = WSMessageEncoding.Mtom;

            binding.MaxReceivedMessageSize = int.MaxValue;

            



            host.AddServiceEndpoint(typeof(IDataUploader), binding, new
Uri("http://localhost:5800/DataUploader"));



            ServiceBehaviorAttribute attribute =
(ServiceBehaviorAttribute)host.Description.Behaviors[typeof(ServiceBehaviorAttribute)];

            attribute.ConcurrencyMode = ConcurrencyMode.Multiple;

            attribute.InstanceContextMode = InstanceContextMode.Single;

			attribute.IncludeExceptionDetailInFaults = true;



            ServiceThrottlingBehavior throttling = new
ServiceThrottlingBehavior();

            throttling.MaxConcurrentSessions = 24;

            throttling.MaxConcurrentCalls = 24;



            host.Description.Behaviors.Add(throttling);            



            host.Open();



            Console.WriteLine("Service Hosted ...");

            Console.ReadKey();

            host.Close();

		}
I have both client and service running on the same system. I get an error:
Object reference not set to an instance of an object error. When I run a
client on a windows system and the service on the linux system I get "bad
request(400) error. Can someone help me understand what I am missing?
-- 
View this message in context: http://mono.1490590.n4.nabble.com/WCF-in-Mono-2-6-7-tp3217763p3217763.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list