【问题标题】:WCF Endpoints & Binding Configuration IssuesWCF 端点和绑定配置问题
【发布时间】:2011-07-06 02:15:45
【问题描述】:

我在这里遇到了一个非常奇怪的问题。为简单起见,我创建了一个项目,其唯一目的是在更大的应用程序框架之外测试问题,但仍然遇到了 Visual Studio 2010 中 WCF 中的错误或与我的 WCF 新手技能集相关的问题:)

问题来了:

我创建了一个在名为“SimpleMethod”的 MVC3 项目中运行的 WCF 端点。该方法在应用程序根目录上的 .svc 文件内运行,并返回一个布尔值。

使用“WCF 服务配置编辑器”,我已将端点以及一个名为“LargeImageBinding”的端点添加到我的 Web.Config。

这里是服务:

    [OperationContract]
    public bool SimpleMethod()
    {
        return true;
    }

还有Config Tool生成的Web.Config:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="LargeImageBinding" closeTimeout="00:10:00" />
  </wsHttpBinding>
</bindings>
<services>
  <service name="WCFEndpoints.ServiceTestOne">
    <endpoint address="/ServiceTestOne.svc" binding="wsHttpBinding"
      bindingConfiguration="LargeImageBinding" contract="WCFEndpoints.IServiceTestOne" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

服务呈现良好,导航到时可以看到端点:http://localhost:57364/ServiceTestOne.svc - 现在,当我创建一个单独的项目来使用该服务时,就会出现问题。我在上面项目的一个运行实例中添加了一个服务引用,指向:http://localhost:57364/ServiceTestOne.svc

这是奇怪的部分。该服务自动生成就好了,但在 Web.Config 中生成的端点如下所示:

<client>
  <endpoint address="http://localhost:57364/ServiceTestOne.svc/ServiceTestOne.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServiceTestOne"
    contract="ServiceTestOne.IServiceTestOne" name="WSHttpBinding_IServiceTestOne">

如您所见,它两次列出了地址的“ServiceTestOne.svc”部分!

当我调用该服务时,我收到以下错误:

远程服务器返回错误:(404) Not Found.

我尝试在上述配置中删除端点地址末尾的额外“/ServiceTestOne.svc”,我得到了完全相同的错误。

现在,如果我返回 WCF 应用程序并删除 Web.Config 中的自定义端点和绑定引用(“服务”和“绑定”标签中的所有内容),然后返回消费者应用程序,那么现在的工作是什么,更新对服务的引用并调用 SimpleMethod()....BOOM 就像一个魅力,我返回一个设置为 true 的 bool。

问题是,我需要进行自定义绑定配置,以便允许在默认值之外访问服务,据我所知,任何创建自定义绑定的尝试都会使端点看起来运行良好,但是进行实际方法调用时失败。

任何人都可以看出我如何将这些放在一起的任何缺陷吗?感谢您抽出宝贵的时间 - 我已经在这个圈子里跑了大约一周!

【问题讨论】:

    标签: asp.net wcf configuration binding service


    【解决方案1】:

    在 IIS 中托管 WCF 服务时,服务的基地址使用以下格式形成:{protocol}://{host}:{port}/{applicationName}/{svcFileName}。这是您可以浏览以获取 WCF 帮助页面和/或元数据(在默认配置下)的地址。

    要形成端点的实际地址(您的客户端需要使用的那个),使用以下格式:{serviceBaseAddress}/{endpointAddress}

    比较上面的格式和您提供的示例配置说明了为什么您在客户端地址中获得了两次 ServiceTestOne.svc。

    如果您希望服务的地址为http://localhost:57364/ServiceTestOne.svc,我建议您在端点配置中将地址属性留空:

    <endpoint address="" ... />
    

    【讨论】:

    • 谢谢拉米罗!这行得通!我还有一个相关的问题,希望你有机会看看:link
    • 其实,这里是我的新问题的链接:link
    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 2011-02-21
    • 2012-02-28
    • 1970-01-01
    • 2012-04-01
    • 2011-02-15
    • 2013-05-29
    相关资源
    最近更新 更多