【问题标题】:Endpoints for a WCF service not found未找到 WCF 服务的终结点
【发布时间】:2023-09-17 10:16:01
【问题描述】:

我创建了 WCF 服务。当我使用 WCF 测试客户端对其进行测试时,该服务运行良好。 我决定配置端点以使用浏览器显示结果。

我有一个空白页面,其中包含 Endpoint not found. 文本,没有更多详细信息。

这是我的 web.config

  <system.serviceModel>

<services>
  <service name="mCollectorService.CollectorService" behaviorConfiguration="mCollectorService.CollectorServiceBehavior">
    <endpoint address="../CollectorService.svc"
              binding="webHttpBinding"
              contract="mCollectorService.ICollectorService"
              behaviorConfiguration="webBehaviour"
              />
  </service>
</services>


<behaviors>
  <serviceBehaviors>
    <behavior name="mCollectorService.CollectorServiceBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

    <protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

这是我的 ICollectorService

[ServiceContract]
public interface ICollectorService
{

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Authenticate/{agentcode}/{pin}/{deviceIMEI}/{gpslat}/{gpslong}")]
    Authentification Authenticate(string agentcode,string pin, string deviceIMEI, string gpslat, string gpslong);

}

任何帮助。

【问题讨论】:

    标签: c# json wcf endpoint


    【解决方案1】:

    尝试像这样修改您的服务:

    <services>
      <service name="mCollectorService.CollectorService" behaviorConfiguration="mCollectorService.CollectorServiceBehavior">
        <endpoint address="../CollectorService.svc"
                  binding="webHttpBinding"
                  contract="mCollectorService.ICollectorService"
                  behaviorConfiguration="webBehaviour"
                  />
        <host>
           <baseAddresses>
               <add baseAddress="http://localhost:51855/CollectorService.svc" />
           </baseAddresses>
    </host>
      </service>
    </services>
    

    并更改您的OperationContract

    [ServiceContract]
    public interface ICollectorService
    {
    
       [OperationContract]
       [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, 
       BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Authenticate/{agentcode}/{pin}/{deviceIMEI}/{gpslat}/{gpslong}")]
        Authentification Authenticate(string agentcode,string pin, string deviceIMEI, string gpslat, string gpslong);
    
    }
    

    并以这种方式调用您的 URL!

    http://localhost:51855/CollectorService.svc/CollectorService.svc/Authenticate/YourAgentCode/YourPin/YourDeviceIMEI/YourGPSLat/YourGPSLong
    

    希望这会有所帮助。谢谢!

    编辑:如果您正在实施身份验证机制,我建议您将请求包装在 JSON 中,而不是在请求 URL 中发送。

    【讨论】:

    • 我按照您的建议尝试过,但没有,仍然给出相同的结果 Endpoint not found.
    • 我遵循Mikes Knowledge base的示例
    • 你看过我的编辑笔记了吗?
    • 是的,但该错误与 web.config 无关。我在 url () 中传递了无效的转义字符。所以他给出了那个错误
    • 我知道!这就是为什么我说不要使用 URL 参数,而是传递 JSON,这是一种正确的方法。否则使用 GET 方法。无论如何,如果它对您有所帮助,请接受此答案并根据您的需要编辑此答案。