开发者

Cannot connect to one of my WCF services, not even with telnet

I have six wcf services that I'm hosting in a windows service. Everything works great on my machine (Windows 7) (Edit: when hosted in Cassini, but not when running through the windows service) but when I try it in production (Windows Server 2003) I cannot connect to one of my six services, ReportsService.

I figured I must have a typo, but everything looks right. I've even rewritten that section of the config file just to be sure.

I've turned on WCF tracing, but it never shows the call to my service; nothing helpful in there.

I tried connecting to the port (9005) with telnet, but it failed. I can connect to all other services (ports 9001-4 and 9006) just fine.

I thought that maybe there was a problem with port 9005, so I changed it to 9007 and still couldn't connect. I had one of my working services host on 9005 and it actually worked fine. So I'm pretty sure there's nothing wrong with the port or any firewall settings. Whatever port I tell ReportsService to use fails.

Now I'm开发者_运维百科 out of ideas. It seems like it's not hosting that one service, but I cannot get any information about why or what's wrong. Any ideas on what I could try to get that information? Or what might be wrong?

The unhandled System.ServiceModel.EndpointNotFoundException I get when running my client is:

Could not connect to net.tcp://localhost:9005/ReportsService. The

connection attempt lasted for a time span of 00:00:01.0937430. TCP error

code 10061: No connection could be made because the target machine

actively refused it 127.0.0.1:9005. .

My host's config file contains:

<!-- Snipped other services to simplify for you. -->
<endpoint binding="netTcpBinding" bindingConfiguration="customTcpBinding" contract="ServiceContracts.IReportsService" />
<endpoint binding="netTcpBinding" bindingConfiguration="customTcpBinding" contract="ServiceContracts.IUpdateData" />

IReportService is the one I'm having trouble with. I get a proxy to IReportsService with the following code, where Server is the name of the hosting machine:

return new ChannelFactory<IReportsService>("").CreateChannel(new EndpointAddress(string.Format("net.tcp://{0}:9005/ReportsService", Server)));

My client config file contains:

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="customTcpBinding" maxReceivedMessageSize="2147483647">
        <readerQuotas maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
        <security mode="None"/>
      </binding>
    </netTcpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata httpGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="True" />
        <serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="30" maxConcurrentSessions="1000" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <!-- Snipped other services to simplify for you. -->
    <service behaviorConfiguration="ServiceBehavior" name="WcfService.ReportsService">
      <endpoint address="ReportsService" binding="netTcpBinding" bindingConfiguration="customTcpBinding"
        contract="ServiceContracts.IReportsService" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:9005" />
        </baseAddresses>
      </host>
    </service>
    <service behaviorConfiguration="ServiceBehavior" name="WcfService.UpdateData">
      <endpoint address="UpdateData" binding="netTcpBinding" bindingConfiguration="customTcpBinding"
        contract="ServiceContracts.IUpdateData" />
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:9006" />
        </baseAddresses>
      </host>
    </service>
  </services>
</system.serviceModel>

I've tried to keep things simple with the code snippets above, but if you would like to see more just ask and I'd be happy to provide anything that'll help.


I'm an idiot. I forgot to create and open a ServiceHost for the ReportsService in my windows service.... I thought everything worked fine on my machine, but really it only worked when hosted in Cassini, not when I actually installed the windows service on my machine. That's what finally tipped me off.

Thanks for the suggestions and for trying to help!


Try using the explicit IP of your box instead of "localhost" throughout your configs. "No connection could be made because the target machine actively refused it 172.0.0.1:9005". 172.0.0.1 looks like a wierd one... Just a guess. Also you might want to check who is listening on what port by running "netstat" on the command line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜