【问题标题】:No endpoint listening at local "..."没有在本地“...”处监听的端点
【发布时间】:2014-08-04 17:19:37
【问题描述】:

我已经获得了 wcf 服务,并且我构建了一个本地控制台应用程序来测试它,但我不断收到标题中显示的此错误。我的服务应该在浏览器中运行,显示它显示示例的屏幕和您可以测试它的 url。错误可能在 Web.config 或 App.config 中。我有这两个文件:

Web.condig

<?xml version="1.0"?>
<configuration>
  <appSettings>
  ...
  </appSettings>
  <system.web>
    <compilation debug="false" targetFramework="4.0"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webHttpBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service name="RAHPEDWCFService.RAHPEDService">
        <endpoint address="http://localhost:44184/RAHPEDService.svc" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RAHPEDWCFService.IRAHPEDService"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IRAHPEDService" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false"
        hostNameComparisonMode="StrongWildcard"
        maxBufferSize="65536" maxBufferPoolSize="524288"
        maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192"
          maxArrayLength="16384" maxBytesPerRead="4096"
          maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:44184/RAHPEDService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IRAHPEDService"
      contract="ServiceReference.IRAHPEDService"
      name="BasicHttpBinding_IRAHPEDService" />
    </client>
  </system.serviceModel>
</configuration>

希望有人能给我提示。

【问题讨论】:

  • WCF 的难点在于读取配置文件。更难的是阅读别人的。更难的是读取 2 个配置文件。
  • 对不起,我知道你了,但我希望有经验的人可以轻松发现一些菜鸟错误。

标签: c# wcf service


【解决方案1】:

请按照以下步骤解决

  1. 请浏览您的服务并单击 URL,无论它是否显示元数据。 例如:http://oj:23/Myservice?wsdl
  2. 如果未启用元数据,则对您的服务配置文件进行以下更改。 一世。创建一个 mex 端点 ii.命名服务行为 前任: 行为> 服务行为> iii.将此行为添加到您的服务中 前任: iv.构建服务并浏览点击 url 检查元数据
  3. 在您的控制台应用程序中,右键单击项目并单击添加服务参考
  4. 将Url放在地址框中,点击Go检查你是否能看到服务,选择你的服务并给出命名空间,然后点击OK
  5. 创建 ServiceClient 的对象
  6. 调用你的方法

能够在浏览器中查看 wsdl 元数据。
如果您的客户端配置文件中有多个端点,那么您已将端点的名称传递给 ServiceCleint 类的构造函数

打开 Visual Studio CommandPrompt 并键入 WcfTestClient,右键单击 MyServiceProjects,添加服务并检查您是否能够添加,一旦添加,就会出现在端点下调用您的方法

【讨论】:

  • 嗨,非常感谢您的回答,是的,确实没有启用元数据,所以我创建了您在每个步骤中指出的内容,并且在浏览器中查看的服务没有启用元数据错误,但在控制台应用程序中仍然会抛出与问题标题中描述的相同的错误。
  • 你能在浏览器中看到wsdl元数据吗
  • 当您将服务添加到控制台应用程序时,您能否找到该服务?如果是,请发布客户端配置文件
  • 如果您的客户端配置文件中有多个端点,那么您已将端点名称传递给 ServiceCleint 类的构造函数
  • 是的,我可以在浏览器中看到元数据,我可以在添加引用时找到服务,这里是我的pastebin.com/t0DQ1rv7 的链接,如果创建了 mex 端点,我应该使用名称对于端点?非常感谢 =)
【解决方案2】:

您应该检查您访问的地址是否正确。与其在 Web.config 中指定整个地址,更常见的做法是只提供一个相对地址(甚至 一个空的“”很好),然后你访问服务:

http://servername:[port]/[virtual directory]/RAHPEDWCF.svc/[relative address in Web.config]

例如如果 Web.config 中的地址显示

endpoint address="MySVC" 

客户端的完整 URL(假设默认端口 80 和虚拟服务器的根目录)可能是

http://servername/RAHPEDWCF.svc/MySVC

如果您能够修改 Web.config,这就是我的建议。

【讨论】:

  • 感谢您的回答,我尝试在 Web.config 文件中输入地址字段,例如 address="", address="localhost:44184",然后将地址留在控制台应用程序中完整的 URI,没有成功。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-06-23
  • 1970-01-01
相关资源
最近更新 更多