locked
Can't get discovery to work when service is hosted using IIS RRS feed

  • Question

  • I am using VS 2010 Beta 2 on Windows 7. If I self-host my WCF, I can write code in a WinForms client and find the endpoint address. However, when I host the service using IIS, the same code returns no endpoints.

    I notice that the doc topic Configuring Discovery in a Configuration File is empty. Does this not work?

    Robert
    Friday, November 13, 2009 10:20 PM

Answers

  • Your service has endpoints, it would not be running if it had none. Have you tried using Add Service Reference to generate your client proxy? Or SvcUtil.exe? Those should work. I have sent you a sample to your email address that shows how this works.

    Hope this helps.
    Monday, November 16, 2009 11:05 PM
    Moderator

All replies

  • That MSDN doc topic is not available yet. It will be available soon.

    Discovery can be completely configured in your web.config/app.config. The way of doing this is via adding a ServiceDiscoveryBehavior and a discovery endpoint.

    Also, can you send us more information about your application? What do you mean with "no endpoints"? Is your service in IIS throwing an InvalidOperationException indicating that it does not have any app endpoint? Or is it just missing the discoveryEndpoint?

    I would also suggest to try some of the discovery samples in MSDN: http://msdn.microsoft.com/en-us/library/dd483326(VS.100).aspx, and see if they run properly for you.
    Saturday, November 14, 2009 12:50 AM
    Moderator
  • Amadeo,

    I will try some of the samples and keep working on it over the weekend. I will let you know Monday how much progress I make.

    Thanks,
    Robert

    Saturday, November 14, 2009 1:02 AM
  • Amadeo,

    I looked at the discovery samples, but they all are based on self-hosted services.

    My WCF service is hosted using Cassini. I add the udpEndpoint and the ServiceDiscoveryBehavior and my Web.config looks like this:

      <system.serviceModel>
        <services>
          <service name="TemperatureService">
            <endpoint name="udpDiscovery"
                      kind="udpDiscoveryEndpoint"/>
          </service>
        </services>
        <protocolMapping>
          <add scheme="http" binding="wsHttpBinding"/>
        </protocolMapping>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceDiscovery/>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    When I right-click the .svc file and View in Browser, the test page tells me "Metadata publishing for this service is currently disabled".

    I assume if the service isn't publishing metadata, the client can't discover endpoints, right?

    So I add the following to Web.config to try and get metadata publishing back:

      <system.serviceModel>
        <services>
          <service name="TemperatureService"
                   behaviorConfiguration="TemperatureServiceBehavior">
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="ITemperatureService">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint contract="IMetadataExchange"
                      binding="mexHttpBinding" address="mex" />
            <endpoint name="udpDiscovery"
                      kind="udpDiscoveryEndpoint"/>
          </service>
        </services>
        <protocolMapping>
          <add scheme="http" binding="wsHttpBinding"/>
        </protocolMapping>
        <behaviors>
          <serviceBehaviors>
            <behavior name="TemperatureServiceBehavior">
              <serviceDiscovery/>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    Still no go. I can't publish metadata when hosting in the Web server and thus, can't find endpoints.

    The client code looks like this, by the way:

      Private proxy As TemperatureServiceClient = Nothing

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _discoveryClient As New DiscoveryClient("udpDiscovery")
        Dim _findCriteria As New FindCriteria(GetType(ITemperatureService))
        Dim _findResponse As FindResponse =
          _discoveryClient.Find(_findCriteria)

        If _findResponse.Endpoints.Count > 0 Then
          proxy = New TemperatureServiceClient( _
            "WSHttpBinding_ITemperatureService")
          proxy.Endpoint.Address =
            _findResponse.Endpoints(0).Address
        Else
          MessageBox.Show("No endpoints found")
        End If
      End Sub

    Robert

    Sunday, November 15, 2009 10:11 PM
  • I just tried this an it works for me. If you give me an email address I can send my sample to you. Based on all the code you published here, everything looks fine to me. The only thing is that I am wondering if the name of your service is not exactly the one you are writing in config, and then your configuration is not being picked up. The config name should be "namespace.classname".

    I am referring to the issue explained in this blog post: http://blogs.msdn.com/endpoint/archive/2009/11/09/common-user-mistake-in-net-4-mistyping-the-service-configuration-name.aspx. Perhaps you are experiencing the same.
    Monday, November 16, 2009 7:00 PM
    Moderator
  • I added the namespace to my Web.config, both for the service and contract name:

    <service name="TemperatureServiceLibrary.TemperatureService"
             behaviorConfiguration="TemperatureServiceBehavior">
    <endpoint address=""
              binding="wsHttpBinding"
              contract="TemperatureServiceLibrary.ITemperatureService">

    At that point, metadata publishing was back.

    However, I still cannot find endoints in my client.

    Can you send me your sample? My email is rgreen at mcwtech.com.

    Thanks,
    Robert
    Monday, November 16, 2009 10:02 PM
  • Your service has endpoints, it would not be running if it had none. Have you tried using Add Service Reference to generate your client proxy? Or SvcUtil.exe? Those should work. I have sent you a sample to your email address that shows how this works.

    Hope this helps.
    Monday, November 16, 2009 11:05 PM
    Moderator
  • Hi Robert

    Discovery and Metadata Exchange are two separate concepts.
    The metadata published through Metadata Exchange is not exactly the same as the one used by Discovery, so they're currently kind of independent from each other.
    I believe your problem is due to the fact that your IIS service is probably not yet activated by the time you're trying to call it (or find it).

    The reason it works with Self Host but not with IIS is that the first one is always open and listening for requests, while the other one is more of an on demand service, going online and offline as needed.
    Since the address in the UDP multicast message is not directly pointing to that service, then the IIS service won't get activated. That's probably why you're not getting any responses.

    Your scenario should work if you manually activate the service before trying to call it using Discovery, by pinging the MEX endpoint or one of the service endpoints.

    What scenario exactly are you trying to achieve? Does Self-Host work for you or do you need to use IIS? There could be different alternatives depending on that

    Hope this helps

    Diego
    Tuesday, November 17, 2009 12:42 AM
  • Hi Diego,

    With help from Amadeo, I finally got this working consistently. Ultimately, it came down to making sure the service was running by right-clicking the .svc file and viewing in browser. That is required for the example where I am using the Cassini Web server. In a demo where I use IIS that step would not be necessary, right?

    Discovery works fine with self-hosting. I just want to create a demo where I show discovery with self-hosting and with Web hosting. So now I have all my scenarios working.

    Thanks,
    Robert
    Tuesday, November 17, 2009 11:40 PM
  • Actually that step would also be required with IIS, because IIS won't activate the service until you actually try to use it (either calling it or navigating to it in the browser)

    Thanks
    Diego
    Wednesday, November 18, 2009 1:24 AM