我在我的 ASP.NET (C#) 应用程序中创建了一个 WCF 休息服务,当我尝试通过以下 Web 浏览器浏览它时,它似乎工作正常 localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc
但是,如果我尝试点击它的其中一个方法,我会收到以下错误消息: localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails
消息:在“http://MachineName.abc.local:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails”没有正在监听的 channel '.这通常是由不正确的地址 URI 引起的。确保消息发送到的地址与服务正在监听的地址相匹配。
契约(Contract):
namespace ABC.WebApp.ExternalServices.WS.SPP.REST
{
[ServiceContract]
public interface ISPPService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetProductionDetail")]
string GetProductionDetail(Stream data);
[OperationContract]
[WebGet]
string GetDetails();
}
}
实现:
namespace ABC.WebApp.ExternalServices.WS.SPP.REST
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SPPService : ISPPService
{
public string GetProductionDetail(Stream xmlRequest)
{
return "hello";
}
public string GetDetails()
{
return "hello2";
}
}
}
.SVC 文件 (SPPService.svc)
<%@ ServiceHost Service = "ABC.WebApp.ExternalServices.WS.SPP.REST.SPPService" Language="C#" %>
Web.Config
<system.serviceModel>
<services>
<service name="ABC.WebApp.ExternalServices.WS.Disb.Rest.DisbService" behaviorConfiguration="defaultBehaviour">
<endpoint name="webHttpsBinding" address="" binding="webHttpBinding" contract="ABC.WebApp.ExternalServices.WS.Disb.Rest.IDisbService"
behaviorConfiguration="webHttp" bindingConfiguration="webHttpTransportSecurity">
</endpoint>
<endpoint name="mexHttpsBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
</service>
<service name="ABC.WebApp.ExternalServices.WS.SPP.REST.SPPService" behaviorConfiguration="defaultBehaviour">
<endpoint name="webHttpsBinding" address="" binding="webHttpBinding" contract="ABC.WebApp.ExternalServices.WS.SPP.REST.ISPPService"
behaviorConfiguration="webHttp" bindingConfiguration="webHttpTransportSecurity">
</endpoint>
<endpoint name="mexHttpsBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="defaultBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
最佳答案
WCF 的一个非常有用的功能是帮助页面。它公开了所有可用的服务以及正确的 URI。
它可以位于:http://MachineName/Service.svc/help .
在我的情况下,它是:localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/help
这让我看到 Web.Config 文件和 IIS 在端口 82 上使用 HTTPS 绑定(bind)。
https://stackoverflow.com/questions/37351497/