views:

485

answers:

4

I have a test project, WCF Service Library, and I published the project. Have a 2003 server with all the right installation. I browse to my application and upon clicking on .svc I get this error.

The type 'SearchService', provided as the Service attribute value in the ServiceHost directive could not be found.

This is the snippet from my web.config

<endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>

My Interface:

  [ServiceContract]
public interface ISearchService
{
    [OperationContract]
    string GetName();
}

My Implementation:

   [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class SearchService :ISearchService
{
    #region ISearchService Members

    public string GetName()
    {
      returnn "HAL-2001" 
    }

 }
A: 

What is your client code calling? For this to work it should be calling a proxy class like the following.

class SearchServiceProxy : ClientBase<ISearchService>, ISearchService
{
    public string GetName()
    {
     return Channel.GetName();
    }
}
Antonio Haley
Antonio,I have not gotten as far as the client. I browsed using IIS and on the web page, I clicked on the .svc file and that is when I got the error. I assume that this may be an issue on my deployment and that is some help I would need with
+2  A: 

Well, the wsHttpBinding requires you to connect to your service using SOAP - a web browser alone won't cut it, so that's why it's not working when you browse to the .svc file. Nothing wrong there, really.

You need to create a real full-fledged SOAP client to connect to your service and test it. Alternatively, you could also use the WcfTestClient.exe test client which sits in your VS2008\Common7\IDE folder.

Marc

marc_s
marc_s: Thanks, I was able to view it with the WcfTestClient application. Upon invoking my method: I got this, 'The caller was not authenticated by the service.' error
Is there a particular reason you're using "PerSession" instancing? The easiest way would be not to specify anything and use "PerCall" instances. Also, this authentication problem could come from your server's config for the service - you'll need to show us the whole thing for us to diagnose what's wrong.
marc_s
A: 

ANo, you should switch over to the basicHttpBinding and test to make sure everything is working. You're using the WSHttpBinding and by default it has authentication turned on. You're client will need to pass credentials for it to actually get a response, that's why the browser call isn't working.

Joshua Belden
+1  A: 

ANo, the error indicates the host could not find the definition for service implementation "SearchService" in your web.config. In you web.config, you need to wrap the <endpoint> tag in a <service> tag. The name attribute of the <service> should be set to the full name of you SearchService class ( including all namespaces). You also need to define a behavior to enable the service to show WSDL in a browser. You may also want to remove the <dns value="localhost" /> when you deploy the service to a server.

Here is an example snippet, make sure your put the full class name of SearchService in <service> tag, and also make sure the full class name is in your .svc file:

<system.serviceModel>
 <services>
  <service name="SearchService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="TestService.ISearchService">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>  </system.serviceModel>
Hongwei Yan