0

I'm trying to compile my c# program using mono inside a docker container.

I have this file inside my Server directory

Server.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace SoapServer
{
    [ServiceContract]
    public interface ISoapServerService 
    {
        [OperationContract]
        string SayHello(string name);
        [OperationContract]
        string CreateRoom();
        [OperationContract]
        List<int> ListRooms();
        [OperationContract]
        bool JoinRoom();
        [OperationContract]
        string Message(string msg);

    }
    
    public class SoapServerService : ISoapServerService
    {
        public string SayHello(string name)
        {
            Console.WriteLine("{0}, is saying Hello.",name);
            return string.Format("Hello, {0}", name);
        }

        public string CreateRoom()
        {
            Random rand = new Random();
            Console.WriteLine("CreateRoom called");
            //create room etc logic here
            return string.Format("Room Created, {0}", rand.Next(100));
        }
        

        public List<int> ListRooms()
        {
            Random rand = new Random();
            Console.WriteLine("ListRooms called");
            //looop through rooms
            return new List<int>() { rand.Next(1000), rand.Next(1000) };
        }

        public bool JoinRoom()
        {
            Console.WriteLine("JoinRoom called");
            Random rand = new Random();
            //add busineess logic
            return rand.Next(100) < 50 ? true : false;
        }

        public string Message(string msg)
        {
            Console.WriteLine("Message received:" + msg);
            return "Message recievied:" + msg;
        }
    }
}

and Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;


namespace SoapServer
{
    
   

     internal class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/");
            // Create the ServiceHost.
            using (ServiceHost host = new ServiceHost(typeof(SoapServerService), baseAddress))
            {
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                // Open the ServiceHost to start listening for messages. Since
                // no endpoints are explicitly configured, the runtime will create
                // one endpoint per base address for each service contract implemented
                // by the service.
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
    }
}

I have no issues compiling Service.cs into a library file, but when I try to run mcs Program.cs -r:Service.dll I get this message

Program.cs(6,14): error CS0234: The type or namespace name ServiceModel' does not exist in the namespace System'. Are you missing System.ServiceModel' assembly reference? Program.cs(7,14): error CS0234: The type or namespace name ServiceModel' does not exist in the namespace System'. Are you missing System.ServiceModel' assembly reference? Compilation failed: 2 error(s), 0 warnings

I don't understand why I'm getting this? I'm using visual studio code and mno through docker. Most solution I found consisted in installing a package to Visual studio, but that does not apply to me.

Raffica
  • 39
  • 4
  • 1
    1. A C# compiler expects you to present all necessary references but you provided nothing at all. 2. Mono does not have full WCF support, https://www.mono-project.com/docs/web/wcf/ So your only option is to use a Windows container with .NET Framework. – Lex Li Mar 31 '22 at 04:36
  • maybe try with xbuild instead of msbuild if your intention is to compile with mono. In that way you can see all exceptions thrown in your docker – phonemyatt Mar 31 '22 at 04:48
  • Not sure might this help https://stackoverflow.com/questions/63094790/issue-with-system-private-servicemodel – Maytham Fahmi Mar 31 '22 at 05:08

0 Answers0