Journeytothe Path
Journeytothe Path

Reputation: 3

Unhandled error in WCF about serviceHostingEnvironment

I'm a newbie trying WCF. I'm trying to access WCF using android, I had trouble and according to my research json is required to access WCF, so I tried changing it to json.

I changed the Interface to an object type and start having an error shown below

The exception message is: The type 'AddItemService.Login', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]

my Interface method:

[OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "Login", BodyStyle = WebMessageBodyStyle.WrappedRequest, 
            ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        [Description("Returns the Login User ID")]
        int GetUserId(Login login);

my web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="AddItemService.Login"
                behaviorConfiguration="RESTBehavior">
        <endpoint address=""
                  binding="webHttpBinding"
                  contract="AddItemService.ILogin"
                   behaviorConfiguration="MyEndpointBehavior"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="RESTBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="MyEndpointBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

I don't know why it won't work. Can anyone please help me?

Upvotes: 0

Views: 635

Answers (1)

Steve Wilkes
Steve Wilkes

Reputation: 7135

Sounds like the service type specified in the .svc file for the WCF service (the actual markup file, not the code-behind one) is referencing a service class type which doesn't exist.

If you right-click the .svc file in the Visual Studio and choose 'View markup', the 'Service' attribute of the ServiceHost directive in that file needs to contain the name of the class which implements your WCF service interface. Sounds like at the moment it's referencing AddItemService.Login, which doesn't exist.

Upvotes: 1

Related Questions