petros
petros

Reputation: 715

How to make WCF service available in a local network?

I'm new in WCF. I wrote a simple service:

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        int Add(int a, int b);
    }
}

namespace WcfService1
{
    public class Service1 : IService1
    {
        public int Add(int a, int b)
        {
            return (a + b);
        }
    }
}

How can I let someone from my local network access this service?

Upvotes: 0

Views: 3078

Answers (4)

Technovation
Technovation

Reputation: 397

you can host your service in your local IIS, just

1-add a web site in IIS and set content directory and port number

2-in content view, look for a file with .svc extension

3-browse your svc file (make sure your file is accessible for IIS_IUSRS group), this is your web service address.

4- others in your network should, right click on their client project and add a service reference.

5-they should paste your web service address, but instead of localhost in web service address, they should use your ip address.

Upvotes: 0

Daniel Gavril
Daniel Gavril

Reputation: 125

Yes, you can. You have to add an endpoint that has netTcpBinding. Also, you have to set the metadata behaviour for netTcp and set the address with net.tcp protocol as I posted in code below.

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding>
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>
<services>
  <service behaviorConfiguration="ServiceBehaviour" name="Service.Service1">
    <endpoint address="net.tcp://localhost:9009/service1"
              binding="netTcpBinding"
              contract="Service.IService1" />
    <endpoint address="mex" 
              binding="mexTcpBinding"
              contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

Upvotes: 1

Jan K&#246;hler
Jan K&#246;hler

Reputation: 6030

There are several ways to host (I think that's what you actually mean by publish in that context) a wcf service:

  1. Hosting in Internet Information Services (IIS)
  2. Hosting in Windows Activation Services (WAS)
  3. Hosting in a Console or Desktop application (Self hosting)
  4. Hosting in a Windows Service

Where often option 1 and 4 are interesting if your service is more than a test project ;-)

Take a look at that tutorial for more information: http://www.codeproject.com/Articles/550796/A-Beginners-Tutorial-on-How-to-Host-a-WCF-Service

Upvotes: 1

jvarleiza
jvarleiza

Reputation: 1

The person needs to add a service reference to your service provided

Here it is: https://msdn.microsoft.com/en-us/library/bb386386.aspx

Upvotes: 0

Related Questions