1

I need to configure an endpoint in my WCF service. My service URL is something like.

http://mysite.com/Services/Service1.svc

I want to give clients the URL http://mysite.com/MyService to consume the service.

I'm tried below in my web.config but it's not working and when I navigate to http://mysite.com/MyService I'm getting the 404 error.

<service name="GateApplication.Services">
   <host>
      <baseAddresses>
         <add baseAddress="http://mysite.com/Services/"/>
      </baseAddresses>
   </host>
   <endpoint 
       address="http://mysite.com/MyService"
       binding="wsHttpBinding" 
       contract="GateApplication.IService1" >
   </endpoint>
</service>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
chamara
  • 12,649
  • 32
  • 134
  • 210
  • How are you **hosting** your WCF service? Inside IIS? If so: then the IIS virtual directory and the path to the `.svc` file defines your service URL, and you cannot just change that via config – marc_s Jun 03 '13 at 07:21
  • @marc_s hello! i'm just started with WCF.As far as i could understand end points are used to give a more user friendly URL for the consumers.Are there any other advantages other than that? and i'm using a shared hosting service which use IIS.please correct me if i'm wrong – chamara Jun 03 '13 at 07:31
  • Endpoints are the connection through which the outside world talks to a WCF service. But when hosting in IIS, the naming of the service URL is dictated by IIS - you cannot easily change it. – marc_s Jun 03 '13 at 07:35
  • If you want full control over the service URL, you need to use **self-hosting** rather than using IIS. [See this MSDN documentation on how to do self-hosting of WCF services](http://msdn.microsoft.com/en-us/library/ms731758.aspx) for starters. – marc_s Jun 03 '13 at 07:42
  • @marc_s so isn't it necessary to use end points always? nothing wrong with a WCF service without using end points right? – chamara Jun 03 '13 at 07:44
  • **NO**! A WCF service without endpoints is pointless..... you cannot communicate with it! The endpoints are **absolutely essential**! – marc_s Jun 03 '13 at 07:45
  • @marc_s hello sorry to bother you. i know the end points are essential on client, for whom consume the service but is it necessary on the server also? i mean the Hosted WCF service.because currently i haven't specified end points on service but the client can communicate if he consumes service through http://mysite.com/Services/Service1.svc – chamara Jun 03 '13 at 08:11
  • Yes, they're essential on **both ends** of your communication! Otherwise, nothing will go. With WCF 4.0, you get *automagic* service endpoints on the server side - you still definitely have endpoints, you just don't have to explicitly define them – marc_s Jun 03 '13 at 08:15

2 Answers2

0

Try the below configuration

<endpoint 
    address="http://mysite.com/Services/Service1.svc"
    binding="wsHttpBinding" 
    contract="GateApplication.IService1" />

go to solution explorer on right click and click on Add service reference and paste

http://mysite.com/Services/Service1.svc

and press ok

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Randhi Rupesh
  • 14,650
  • 9
  • 27
  • 46
0

I assume you are hosting on IIS.

In essense you can't just choose address in IIS in a way you can do it with self-hosting. However you can use either routing or dynamic path re-writing to have user redirected from the alias to your SVC

There are plenty of links about it. For example you can use this answer or this answer as a reference.

Community
  • 1
  • 1
Igor Popov
  • 2,084
  • 16
  • 18