Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;您正在查找的资源(或其依赖项之一)“;错误WCF REST_C#_Rest_Wcf - Fatal编程技术网

C# &引用;您正在查找的资源(或其依赖项之一)“;错误WCF REST

C# &引用;您正在查找的资源(或其依赖项之一)“;错误WCF REST,c#,rest,wcf,C#,Rest,Wcf,我有一个RESTful服务无法工作,尽管我验证了所有代码:web.config、Iservic和实现: IServiceImport: namespace SysLap.Services.Web.ImportAutoLiasse { [ServiceContract] public interface IServiceImportAutoLiasse { [OperationContract] [WebGet] string GetData(int value);

我有一个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>
我有一个错误:

  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等服务,我比较了其中的代码,一切都很好

我在使用邮递员时获得以下信息:

[EndpointNotFoundException]: There was no channel actively listening at &#39;https://localhost:44355/ServiceImportAutoLiasse.svc/rest/GetData?value=19&#39;. 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 &#39;https://localhost:44355/ServiceImportAutoLiasse.svc/rest/GetData?value=19&#39;. 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)

我怎样才能修好它?谢谢,

服务的名称属性和合同不能随意更改。它应该是实际的完全限定服务实现类和服务接口,服务接口由名称空间、句点和类型名组成。例如
WcfService1.Service1

因此,上面的接口定义和服务实现与服务部分中的以下属性不对应

<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>

请参阅官方文件。

已更新。
已配置的WCF服务仅在HTTP协议上工作,而不是在HTTPS上工作,为了在HTTPS上工作,我们需要使用传输安全模式配置额外的服务端点

    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="myb">
        <endpoint address="soap" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <endpoint address="rest" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="restbeh"></endpoint>
      <endpoint address="rest" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="restbeh" bindingConfiguration="httpsbinding"></endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="httpsbinding">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
</bindings>


如果有什么我可以帮忙的,请随时告诉我。

谢谢你的回复,我很抱歉名字的错误,这是我的错,现在很好,我检查了名字prperty和合同,但始终是相同的问题!那么,我们应该做些什么来修复它呢?感谢您的代码片段中仍然存在一些小错误,请仔细检查并提出问题。就我而言,它工作正常。请仔细检查客户端的调用。服务地址可能有问题,很奇怪!我修改了我的帖子:我添加了服务地址,地址是确定的,为了使WCF Web Http服务通过HTTPS协议工作,我们需要使用传输安全模式配置一个额外的服务端点。请参阅我的最新回复。
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="myb">
        <endpoint address="soap" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
        <endpoint address="rest" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="restbeh"></endpoint>
      <endpoint address="rest" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="restbeh" bindingConfiguration="httpsbinding"></endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="httpsbinding">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
</bindings>