我在客户端计算机上运行了NetTcp Self Hosting服务,并且在服务器上的IIS上运行了另一个NetTcp服务。我试图从IIS中的服务使用自托管服务。它抛出超时错误的异常。
我使用WCF测试客户端来测试自托管服务,它运行正常。此外,我编写了一个示例C#应用程序,它调用自托管服务,并且工作正常。只有当IIS上的服务尝试调用时,才会失败。
我猜它在IIS上必须有一些安全设置,这会阻止外出呼叫,从而导致超时。任何线索?
拨打自助托管服务的代码:
private object CallClient(string message)
{
var myBinding = new NetTcpBinding(SecurityMode.None);
var myEndpoint = new EndpointAddress("net.tcp://<myIP>:8188/MessageReceiverService/");
var myChannelFactory = new ChannelFactory<IMessageReceiverService>(myBinding, myEndpoint);
IMessageReceiverService client = null;
var result = new MessageCenterResponse { Result = message };
try
{
client = myChannelFactory.CreateChannel();
result.Result += client.TestMethod("Shankar");
}
catch (Exception ex)
{
if (client != null)
{
((ICommunicationObject)client).Abort();
}
result.Result += "Exception!!" + myEndpoint.Uri + " - " + ex.Message;
}
finally
{
((ICommunicationObject)client).Close();
}
return result;
}
邮件接收方服务(在自托管服务上):
public bool TestMethod(string testMessage)
{
return testMessage.Equals("Shankar");
}
以上代码在从独立应用程序调用时工作正常,但在行之后从IIS调用时失败:client.TestMethod("Shankar");
这就是我启动自托管服务的方式:
private void StartMessageCenterService()
{
var tcpUrl = new Uri("net.tcp://<myIP>:8188/MessageReceiverService/");
var messageCenterHost = new ServiceHost(typeof(MessageReceiverService), tcpUrl);
messageCenterHost.Faulted += MessageCenterHost_Faulted;
messageCenterHost.Open();
}
App.config中的自托管WebService代码:
<services>
<service name="MessageCenter.Proxy.VirtualServer.MessageReceiverService" behaviorConfiguration="DebugServiceBehavior">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="InsecureTcp"
behaviorConfiguration="LargeDataEndpointBehavior"
contract="MessageCenter.Common.Interfaces.IMessageReceiverService">
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>