2011-10-03 105 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看來有些事情會導致您的服務失敗。

尼克拉斯