【问题标题】:How to visit wcf service via endpoint address?如何通过端点地址访问 wcf 服务?
【发布时间】:2016-01-12 08:06:29
【问题描述】:

我通过使用 VS2013 创建 wcf 应用程序项目来创建 wcf 服务。 我的服务合同是 IWCFService,我有一个名为 WCFService 的 IWCFService 实现

 [ServiceContract]
    public interface IWCFService
    {
        [OperationContract]
        void DoWork();
    }

public class WCFService : IWCFService
    {


        public void DoWork()
        {

          //do something
        }
}

我的服务配置如下:

<system.serviceModel>
    <services>
      <service name="WcfService2.WCFService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
          contract="WcfService2.IWCFService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5831/WCFService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

当我启动我的应用程序时,我可以通过 url http://localhost:5831/WCFService.svc 添加服务引用,但是当我尝试通过 http://localhost:5831/WCFService 添加服务引用时,发现发现。为什么我在 web.config 中定义的地址没有帮助?

【问题讨论】:

    标签: c# web-services wcf


    【解决方案1】:

    &lt;baseAddresses&gt; 仅在您的服务托管在自托管环境中时才有效。

    表示baseAddress元素的集合,它们是base 自托管环境中服务主机的地址。如果一个基地 地址存在,端点可以配置地址 相对于基地址。

    【讨论】:

    猜你喜欢
    • 2013-09-14
    • 2019-12-30
    • 2017-12-05
    • 2011-10-19
    • 1970-01-01
    • 2017-05-10
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多