2011-10-03 89 views
5

我已经在linux和os x上都试过这个,并且遇到同样的问题。这是MonoDevelop 2.6和最新的Mono稳定版本。在我的Mac上这就是2.10.2。Mono中的WCF服务无法访问?

这个用于几天前为我工作。我将浏览器指向“http:// localhost:8000/number/test”,并会得到一条消息,内容如下所示:“在命令行中键入svcutil http:// localhost:8000/number/test [somethingmore] “

现在我在Linux和Mac获得在浏览器中的信息是:

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"> 

a:InternalServiceFault 服务器由于内部错误,无法处理请求。服务器可能能够返回异常详细信息(这取决于服务器设置)。

这用来工作,所以我不知道如果我失去了一些重要的东西,或者如果事情是错单或什么。我希望你有一个想法。从MSDN教程中可以看出,这一切都非常直白(有一些变化)。 (对于那些知道的人,我知道这到目前为止还不能保存状态,因为它还没有建立会话,我正在努力到达那里,当我得到这个错误)。

这里是我的课:

using System; 
using System.ServiceModel; 

namespace NumberService 
    { 
[ServiceContract] 
public interface INumberService 
{ 
    [OperationContract] 
    void Add(int val); 

    [OperationContract] 
    void Subtract(int val); 

    [OperationContract] 
    int Result(); 
} 
} 

using System; 

namespace NumberService 
{ 
public class NumberService : INumberService 
{ 
    private int val = 1; 


    public NumberService() 
    { 
     Console.WriteLine("NumberService created."); 
    } 

    public void Add(int val) 
    { 
     this.val += val;  
    } 

    public void Subtract(int val) 
    { 
     this.val -= val; 
    } 


    public int Result() 
    { 
     return val; 
    } 
} 
} 



using System; 
using System.ServiceModel; 
using System.ServiceModel.Description; 

namespace NumberService 
{ 
class MainClass 
{ 
    public static void Main (string[] args) 
    { 
     Uri uri = new Uri("http://localhost:8000/number/test"); 

     ServiceHost selfHost = new ServiceHost(typeof(NumberService), uri); 


     try 
     { 


      // Step 3 of the hosting procedure: Add a service endpoint. 
      selfHost.AddServiceEndpoint(
       typeof(INumberService), 
       new WSHttpBinding(SecurityMode.None), 
       "NumberService"); 


      // Step 4 of the hosting procedure: Enable metadata exchange. 
      ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 
      smb.HttpGetEnabled = true; 
      selfHost.Description.Behaviors.Add(smb); 

      // Step 5 of the hosting procedure: Start (and then stop) the service. 
      selfHost.Open(); 
      Console.WriteLine("The service is ready."); 
      Console.WriteLine("Press <ENTER> to terminate service."); 
      Console.WriteLine(); 
      Console.ReadLine(); 

      // Close the ServiceHostBase to shutdown the service. 
      selfHost.Close(); 
     } 
     catch (CommunicationException ce) 
     { 
      Console.WriteLine("An exception occurred: {0}", ce.Message); 
      selfHost.Abort(); 
     } 


    } 


} 
} 
+0

唉它适用于Windows 7 - Visual Studio和单声道 –

回答

1

你有没有尝试访问该服务时要调试? 从InternalServiceFault看来有些事情会导致您的服务失败。

尼克拉斯