简体   繁体   中英

How to access wcf service from another computer?

I have a wcf service and i install it as windows service. I can access this service from 192.168.2.6 machine:

"net.tcp://192.168.2.5:2025/Services/mex".

i want to access this service from another computer using static ip and port.

How can access this service ?

I tried to connect net.tcp://staticIp:port/Services/mex and i got error :

Metadata contains a reference that cannot be resolved: 'net.tcp://[staticIP]:[port]/Services/mex'.If the service is defined in the current solution, try building the solution and adding the service reference again.

(I navigate my [port] to inside port 2025)

my config:

<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IServices" />
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://192.168.2.5:2025/Services" binding="netTcpBinding"
    bindingConfiguration="NetTcpBinding_IServices" contract="myServices.IServices"
    name="NetTcpBinding_IServices">
    <!--<identity>
      <dns value="localhost" />
    </identity>-->
  </endpoint>
</client>
<services>
  <service name="F8ShadowWcfLib.Services">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
      contract="F8ShadowWcfLib.IServices">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://192.168.2.5:2025/Services" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Edit1:

I remove tag from config and i add it at runtime.

myService.ServicesClient myServ = new myService.ServicesClient();
            EndpointAddress myEndpointAdd = new EndpointAddress(new Uri("net.tcp://[staticIP]:[port]/Services") ,
                                                EndpointIdentity.CreateDnsIdentity("net.tcp://f8srv.f8.com.tr:2299/Services"));

myServ.Endpoint.Address = myEndpointAdd;

I got different error : The server has rejected the client credentials.

The problem is probably related to this part:

<identity>
    <dns value="localhost" />
</identity>

This work work locally because localhost makes sense locally, but across a network it doesn't.

You can validate this identity in a number of ways, such as specifying the UPN (user principal name) of the user running the service, or an SPN (Server Principal Name) of the server running the service (although for this you'll have to register a SPN).

This article should explain it a little:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

To allow seperate connection set AddressFilterMode : Any and set your identy both service and client side.

This article about identy settings:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

 [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
   public class Services : IServices
   {
        .
        .
        .
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM