【问题标题】:Accessing to a wcf service访问 wcf 服务
【发布时间】:2013-04-09 18:18:04
【问题描述】:

我有问题。 我尝试从应用程序 ASP.net MVC 访问 wcf Web 服务,但在调用该方法时出现此异常。

在 URI 上没有可以接受的端点监听 信息。这通常是由不正确的地址或 SOAP 操作引起的。 有关详细信息,请参阅 InnerException(如果存在)。

这是我的代码

var client = new DSServiceClient();
client.Methode();

web.config 的服务模型部分

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IDSService" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="localhost:1695/Service1.svc"; binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDSService" contract="ServiceReference1.IDSService" name="BasicHttpBinding_IDSService" />
    </client>
</system.serviceModel>

【问题讨论】:

  • 您的代码很好命名为Methode
  • 仅供参考,它是“WCF 服务”,而不是“WCF”

标签: wcf


【解决方案1】:

检查您使用的 URL 是否可以从 asp.net mvc 站点访问。如果您使用的是 http 绑定,则可以将 url 复制并粘贴到部署站点的服务器上的浏览器中。该 URL 应位于站点根文件夹的 web.config 文件中。

【讨论】:

  • localhost:1695/Service1.svc" binding= "basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDSService" contract="ServiceReference1.IDSService" name="BasicHttpBinding_IDSService" />
  • 当我复制和粘贴时,我不知道最后是一个斜线,响应是找不到端点。
  • 如果你打开浏览器,访问localhost:1695/Service1.svc你会得到什么?
  • 所以,当我从 vs2012 运行我的服务时,右键单击 Service.svc 并在浏览器上运行,就可以了。当我访问 localhost:1695/Service1.svc/Methode1 时也可以。此外,当我在 IIs 中托管服务时,也可以。
  • 但问题是当我在 ClientProject 中调用方法时
【解决方案2】:

您是否使用 IIS 7 进行托管?如果这样,您可以访问您的站点,启用目录浏览(暂时),单击 IIS 管理器右侧的浏览链接,选择服务类(“something.svc”),它应该会在浏览器中弹出。此时,您可以从浏览器复制 URL 并将 localhost 替换为服务器名称。您甚至可以继续单击该页面上的顶部链接以访问 WSDL。如果出现问题,您可能会收到一条可能更有帮助的错误消息。

【讨论】:

  • 我没有找到浏览链接。:(
  • Erreur HTTP 404.3 - Not Found La page que vous avez demandée ne peut pas être traitée en raison de la configuration d'extension。 Si la page est un script, ajoutez un gestionnaire。 Si le fichier doit être téléchargé, ajoutez un mappage MIME。
  • 现在您应该知道 URL 是什么了,mais j'ai pas vraiment contains la message d'error ,您的 .svc 文件可能有错误,您是否在端点上使用了行为扩展?您应该从服务中发布您的端点和服务配置。
  • 所以,忘记我纠正它的最后一个错误。我在 IIS 上托管了我的服务,没关系。但是当我托管 ClientProject 时出现错误:[WebException:无法连接到远程服务器]和[EndpointNotFoundException:在localhost:1695/Service1.svc 处没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。]
  • 取本地打开服务的URL,粘贴到你的测试机上运行的浏览器中,把localhost改成正确的服务器名,能用吗?
【解决方案3】:

这是我的服务的 web.config

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpEndpointBinding">
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
        realm="" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="DSWebService.Service1Behavior"
    name="DSWebService.Service1">
    <endpoint address="" binding="wsHttpBinding"
      contract="DSWebService.IDSService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:1695/DSWebService" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="DSWebService.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="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>
</behaviors>

这是我的客户端的 web.config:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IDSService" />
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:1695/Service1.svc" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IDSService" contract="IDSService"
      name="WSHttpBinding_IDSService">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</client>

两个项目应该在同一个解决方案上,并且在我们添加参考之后:

DSServiceClient client = new DSServiceClient();

client.Methode();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2011-08-19
    • 2017-05-10
    • 2014-10-09
    相关资源
    最近更新 更多