***你能根据我的程序类提供app.config文件吗?
如果可能,请提供 app.config 代码,我明白了你的意思,但对于你所说的,我不知道该怎么做***
此代码不起作用,因为它在到达时导致错误host.open()
。请帮我解决问题
public class Program
{
static void Main(string[] args)
{
// Base address
Uri baseServiceAddress = new Uri("http://localhost:8090/Welcome");
using (var host = new ServiceHost(typeof(WCFSelfHostedService), baseServiceAddress))
{
// Enable MetaData publishing.
ServiceMetadataBehavior serviceMetaDataBehaviour = new ServiceMetadataBehavior();
serviceMetaDataBehaviour.HttpGetEnabled = true;
serviceMetaDataBehaviour.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(serviceMetaDataBehaviour);
// Open the ServiceHost to start listening for messages. No endpoint are explicitly defined, runtime creates default endpoint.
host.Open();
Console.WriteLine("The service is ready at {0} and host at {1}", baseServiceAddress, DateTime.Now.ToString());
Console.WriteLine("The service and client is running in the same process.");
WCFSelfHostedService selfHostService = new WCFSelfHostedService();
Console.Write("Enter your name. : ");
Console.WriteLine(selfHostService.WelComeMessage(Console.ReadLine()));
Console.WriteLine("Host is running... Press <Enter> key to stop the service.");
Console.ReadLine();
//Close the service.
host.Close();
}
}
}
当我运行此代码时,我收到此错误:
System.ServiceModel.dll 中出现“System.InvalidOperationException”类型的未处理异常
附加信息:服务 'WCFSelfHostedService.WCFSelfHostedService' 的应用程序(非基础设施)端点为零。这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在服务元素中没有定义端点。
我app.config
的是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint
address ="localhost:8090/Welcome";
binding ="wsHttpBinding"
contract ="MyCalculatorService.ISimpleCalculator">
</endpoint>
</client>
</system.serviceModel>
</configuration>