我将 WCF 服务 (.NET 3.5) 部署到 IIS 5.1 (WinXP) 并且可以从本地计算机访问。但是,它不能在本地计算机之外访问。
这是我的 web.config 文件:
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://222.22.22.222:8072/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="Parus.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://111.1.11.111:8072/AsurReceiveData/Service.svc"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<MyInspector />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Parus.ServiceBehavior" name="Parus.Service">
<endpoint address="http://222.22.22.222:8072/AsurReceiveData/Service.svc" binding="basicHttpBinding" contract="Parus.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="MyInspector" type="Parus.MessageInspectorExtension, Parus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
计算机的本地IP地址为:111.1.11.111:8072。计算机的公网IP地址为:222.22.22.222:8072。
我做了什么?我在 IIS 5.1 中添加了新的 TCP 端口(默认网站属性 -> 网站选项卡 -> 单击高级按钮 -> 单击添加按钮并添加新端口:8072)。
项目 URL 如下所示:
http://111.1.11.111:8072/ServiceFolder
该服务如下所示:
public class Service : IService
{
public const string ReplyAction = "http://222.22.22.222:8072/AsurReceiveData/Message_ReplyAction";
public const string RequestAction = "http://222.22.22.222:8072/AsurReceiveData/Message_RequestAction";
public Message SetData(Message requestXml)
{
using (StreamWriter writer = File.CreateText(@"Path\Body.xml"))
{
writer.WriteLine(requestXml.ToString());
}
Message response = Message.CreateMessage(MessageVersion.Default, ReplyAction, requestXml.ToString());
return response;
}
}
我不确定我是否正确使用本地和公共 IP 地址。也许是别的什么...
我很感激任何帮助。