我已经在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">
Run Code Online (Sandbox Code Playgroud)
__CODE__
由于内部错误,服务器无法处理请求.服务器可能能够返回异常详细信息(这取决于服务器设置).
这曾经有用,所以我不确定我是否遗漏了一些重要的东西,或者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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1053 次 |
| 最近记录: |