4

I have been trying to add a new endpoint in a service hosted under IIS but haven't been able to figure it out for the past day or so.

This is my understanding:

  • you can have multiple endpoints under IIS as long as they have unique addresses.
  • you could assign a base address but it will be overridden by the virtual directory setup in IIS.

My virtual directory is http://localhost/WcfCert/

<services>
  <service name="WcfCertServer.Service1" behaviorConfiguration="WcfCertServer.Service1Behavior">
    <endpoint address="" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
    <endpoint address="test" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>

I can bring up the service using http://localhost/wcfcert/service1.svc

but http://localhost/wcfcert/test/service1.svc/test doesn't return anything in IE or the client app

what am I missing here?

Edit:

So i did further testing, and here is what i discovered.

if i start WcfTestClient.exe and add either http://localhost:1523/Service1.svc or http://localhost:1523/Service1.svc/mex it will add both the endpoint under that address. so here is my question shouldn't http://localhost:1523/Service1.svc only represent the first endpoint? why adding that address bring up both endpoints?

but if I try to add http://localhost:1523/Service1.svc/test I get

Error: Cannot obtain Metadata from http://localhost:1523/Service1.svc/test If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:1523/Service1.svc/test Metadata contains a reference that cannot be resolved: 'http://localhost:1523/Service1.svc/test'. Sendera:BadContextTokenThe message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.HTTP GET Error URI: http://localhost:1523/Service1.svc/test There was an error downloading 'http://localhost:1523/Service1.svc/test'. The request failed with HTTP status 400: Bad Request.

kay.one
  • 7,622
  • 6
  • 55
  • 74
  • 2
    I have a similar problem. I'd love to get a solution to this. The only difference to what you describe seems to be that I get a '400 Bad request' with no text. I'm following the description on http://msdn.microsoft.com/en-us/library/ms733766.aspx which states in the comment that the resulting URL would be - translated to your example - http://localhost/wcfcert/service1.svc/test . It does not work for me either. – Evgeniy Berezovsky Aug 03 '11 at 06:43
  • The URL does not work in IE (.../Service1.svc/test). But create proxy add the same endpoint it works. Refer this http://msdn.microsoft.com/en-us/library/ms751515(v=vs.110).aspx – Prasad Kanaparthi Dec 07 '13 at 00:39

2 Answers2

2

It would actually be:

http://localhost/wcfcert/service1.svc/test

If you want the URL to be 'http://localhost/wcfcert/test/service1.svc', then you will need to specify the full URL in the address attribute.

jrista
  • 32,447
  • 15
  • 90
  • 130
  • @Keivan: For the second option, did you set address="http://localhost/wcfcert/test/service1.svc", or just leave it at address="test"? If you want the URL to be http://localhost/wcfcert/test/service1.svc, then you need to make sure you specify the full address in the address attribute. – jrista Jul 25 '09 at 19:12
  • I have tried both "localhost/wcfcert/test/service1.svc" and "localhost/wcfcert/service1.svc/test" – kay.one Jul 25 '09 at 20:17
  • I have edited the question, i don't need any specific url, I'm just trying to have more than one endpoint. – kay.one Jul 25 '09 at 20:22
  • @Keivan: To have more than one endpoint, you either need to use different transport protocols for the bindings for each endpoint, or for multiple endpoints with the same protocol, you need unique URL's. Since you are using the wsHttp binding for both (disregarding the mex), you need to have unique URL's for each endpoint. It sounds like you have it configured correctly....so I am currently at a loss as to why you are getting a 400 error. – jrista Jul 25 '09 at 20:43
  • out of curiosity, have you gotten it to work on your computer? – kay.one Jul 25 '09 at 23:46
  • I use WCF regularly, and I've encountered my fair share of little issues getting things to work at times. Nevertheless, in the end, I have always managed to get my services working and properly hosted. Just out of curiosity...are you using IIS 7 or 6? If you are using IIS 6, make sure you have mapped the .svc extension to the ASP.NET ISAPI handler. – jrista Jul 26 '09 at 01:48
  • its running under windows 7, IIS 7. – kay.one Jul 26 '09 at 03:22
0

I ran into a similar problem recently, and I believe the reason is because the WcfTestClient requires the mex endpoint to query the metadata for the service it is testing.

When you add the service address "http://localhost:1523/Service1.svc" to the WcfTestClient, it actually queries the endpoint "http://localhost:1523/Service1.svc/mex" to get the service description.

The error "Cannot obtain Metadata from "http://localhost:1523/Service1.svc/test" is displayed because the WcfTestClient is looking for the "/test/mex" endpoint to get the metadata for the service at "/test".

To fix this, you need to add another endpoint to provide metadata about the service hosted at address "/test":

<endpoint address="/test/mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

This is the solution that worked for me.

MrUpsideDown
  • 638
  • 7
  • 7