spa*_*guy 0 c# wcf soap windows-services
我正在尝试构建一个相当基本的WCF SOAP Web服务,作为Windows服务自托管.Windows服务本身在我的机器上启动并运行 - 我无法通过Visual Studio或Web浏览器在本地访问它.
相关的C#代码如下.假设MyDummyService实施合同IDummyService:
public class Program : ServiceBase
{
private ServiceHost host = null;
private readonly Uri baseAddress = new Uri("http://localhost:8000/DummyAPI");
public static readonly ILog log = LogManager.GetLogger(typeof(Program));
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
ServiceBase.Run(new Program());
}
public Program()
{
this.ServiceName = "DummyService";
}
protected override void OnStart(string[] args)
{
log.Info("Starting service");
try
{
base.OnStart(args);
host = new ServiceHost(typeof(MyDummyService), baseAddress);
host.Open();
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
finally
{
if (host != null)
((IDisposable)host).Dispose();
}
}
protected override void OnStop()
{
log.Info("Stopping service");
base.OnStop();
host.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
相关app.config:
<system.serviceModel>
<services>
<service name="DummyAPI.MyDummyService"
behaviorConfiguration="MyDummyBehavior">
<endpoint
address=""
binding="basicHttpBinding"
contract="DummyAPI.IDummyService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyDummyBehavior">
<serviceMetadata httpGetEnabled="True" policyVersion="Policy15"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
当我访问
http://localhost:8000/DummyAPI
Run Code Online (Sandbox Code Playgroud)
要么
http://localhost:8000/DummyAPI/MyDummyService
Run Code Online (Sandbox Code Playgroud)
(或其中任何一个后面跟着?wsdl)在网页浏览器中,我得到了404.显而易见的第一个问题:我上面有什么问题?
该web.config命名空间(或者是什么样子的命名空间)中有我有点困惑.我可以安全地在现场做些什么,以及需要反映C#类命名空间的内容是什么?
看起来您正在使用Start方法处理ServiceHost,这种方法在没有运行ServiceHost的情况下有效地离开了您.
finally
{
if (host != null)
((IDisposable)host).Dispose();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1102 次 |
| 最近记录: |