[英]Console Hosting WCF service Http accessible under mono and IIS
[英]WCF Service in Mono not accessible?
我在linux和os x上都嘗試過這個問題並且遇到了同樣的問題。 這是具有最新穩定版Mono的MonoDevelop 2.6。 在我的Mac上,即2.10.2。
這幾天前曾經對我有用。 我會將我的瀏覽器指向“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
由於內部錯誤,服務器無法處理請求。 服務器可能能夠返回異常詳細信息(這取決於服務器設置)。
這曾經有用,所以我不確定我是否遺漏了一些重要的東西,或者Mono或者是什么問題。 我希望你有個主意。 這一切都非常直接來自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();
}
}
}
}
您在調試時是否嘗試訪問該服務? 從InternalServiceFault
,似乎有些事情導致您的服務失敗。
尼克拉斯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.