【问题标题】:How to host WCF service in IIS 5.1?如何在 IIS 5.1 中托管 WCF 服务?
【发布时间】:2012-12-11 12:16:04
【问题描述】:

我使用 VS2008 和 .NET 3.5。

这是我的情况:

1) 外部服务:

我使用外部服务(对其代码一无所知;对我来说它是黑匣子)并调用它的方法,该方法需要几个参数。其中之一是我应该写的 WCF 服务的地址(见 2))。调用如下所示:

string Url = "http://public-ip:8072/Service.svc";
string content = extClient.Method1(Url, email, param1, param2...);

在 Method1 的某个地方,他们从 2) 调用我的服务。

2) 我的服务:

public class Service : IService
{
    public const string ReplyAction = "http://public-ip:8072/Message_ReplyAction";
    public const string RequestAction = "http://public-ip:8072/Message_RequestAction";

    public Message SetData(Message requestXml)
    {
        // Do something
    }
}

Web.config:

<system.serviceModel>
  <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
      <add prefix="http://public-ip:8072/"/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Parus.ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpGetUrl="http://local-ip:8072/Service.svc"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="Parus.ServiceBehavior" name="Parus.Service">
      <endpoint address="http://public-ip:8072/Service.svc" binding="basicHttpBinding" contract="Parus.IService">
      </endpoint>
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

当我在本地使用我的服务时,它可以工作,但当我将它暴露给全世界时,它就不行了。我的意思是 1) 中的 Method1 根本不调用它。我尝试了不同的事情,但到目前为止没有任何反应。防火墙关闭时它不起作用。另外,添加防火墙的8072端口例外时也不起作用。

我想我在 Web.config 文件中做错了什么或错过了 IIS 中的一些设置。您可以关注 Web.config 文件中的 public-ip 和 local-ip 地址。也许我对他们犯了错误。我不确定。

【问题讨论】:

标签: wcf iis deployment


【解决方案1】:

当服务在本地运行但不是通过公共 IP 地址运行时,通常是以下两种情况之一:

  • 防火墙正在阻止请求。在这里,我看到您写道您打开了端口。试试telnet测试一下,可能有好几层阻塞了端口,你只打开了一层。
  • 配置。您在 web.config 中混合使用公共和私有 IP 地址,尝试将所有内容设置为公共 IP 地址。

【讨论】:

  • 我希望我的服务不仅可以在本地公开,还可以在互联网上公开。
  • 我已将 Web.config 文件中的所有地址设置为相同 - 公共 IP,但一切都相同,这意味着我的服务未执行。
  • 我真的不知道下一步该做什么。
  • 检查iis日志,看看请求是否到达iis
  • IIS 日志中没有关于外部调用的内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-13
  • 2020-04-26
  • 1970-01-01
  • 2012-08-18
  • 2012-07-06
  • 1970-01-01
相关资源
最近更新 更多