【发布时间】:2020-04-05 22:30:24
【问题描述】:
我有一个 RESTful 服务无法运行,尽管我验证了所有代码:web.config、Iservic 和实现:
IServiceImport:
namespace SysLap.Services.Web.ImportAutoLiasse
{
[ServiceContract]
public interface IServiceImportAutoLiasse
{
[OperationContract]
[WebGet]
string GetData(int value);
}
}
ServiceImport.svc.cs:
namespace SysLap.Services.Web.ImportAutoLiasse
{
public class ServiceImportAutoLiasse: IServiceImportAutoLiasse
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
Web.config:
<system.serviceModel>
<services>
<!--SOAP-->
<service behaviorConfiguration="ServBehavior" name="SysLap.Services.Web.ImportAutoLiasse.ServiceImportAutoLiasse">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration=""
contract="SysLap.Services.Web.ImportAutoLiasse.IServiceImportAutoLiasse" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<!--REST-->
<endpoint address="rest" behaviorConfiguration="restBehavior"
binding="webHttpBinding" bindingConfiguration="" contract="SysLap.Services.Web.ImportAutoLiasse.IServiceImportAutoLiasse" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
当我测试 SOAP 时,它运行良好, 但如果我测试 wcf REST:
https://localhost:44355/ServiceImportAutoLiasse.svc/rest/GetData?value=19
我有这个错误:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed,
had its name changed, or is temporarily unavailable. Please review the following URL and make sure
that it is spelled correctly.
另一方面,我有其他 wcf 项目包含 SOAP 和 REST 等服务,我比较了其中的代码,一切都很好!
我在使用 POSTMAN 时得到这些信息:
[EndpointNotFoundException]: There was no channel actively listening at 'https://localhost:44355/ServiceImportAutoLiasse.svc/rest/GetData?value=19'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
[HttpException]: There was no channel actively listening at 'https://localhost:44355/ServiceImportAutoLiasse.svc/rest/GetData?value=19'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
at System.ServiceModel.Activation.ServiceHttpHandlerFactory.ServiceHttpHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar)
at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
我该如何解决?谢谢,
【问题讨论】: