0
votes

I'm hosting my WCF service on IIS 7, even though it is working fine when using the WCF Test Client, I cannot consume my service from a simple console application.

I've already allowed the handling of .svc and .wsdl files on my IIS. I'm not sure what else am I missing.

Here is my code:

namespace EvalServiceLibrary {
    [ServiceContract]
    public interface IEvalService {
        [OperationContract]
        void SubmitEval(Eval eval);

        [OperationContract]
        List<Eval> GetEvals();

        [OperationContract]
        void RemoveEval(String id);
    }
}

namespace EvalServiceLibrary {
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class EvalService : IEvalService {
        #region
        List<Eval> evals = new List<Eval>();

        public void SubmitEval(Eval eval) {
            eval.Id = Guid.NewGuid().ToString();
            evals.Add(eval);
        }

        public List<Eval> GetEvals() {
            return evals;
        }

        public void RemoveEval(String id) {
            evals.Remove(evals.Find(e => e.Id.Equals(id)));
        }
        #endregion
    }
}

And my web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="EvalServiceLibrary.EvalService">
        <endpoint address="http://localhost/WebEvalService" binding="basicHttpBinding"
          bindingConfiguration="" name="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Here's my client code:

static void Main(string[] args) {
            EvalServiceClient client = new EvalServiceClient();

            client.SubmitEval(new Eval() { Comments = "Lorem Ipsum", Submitter = "egarcia", TimeSubmitted = DateTime.Now });

            List<Eval> evalList = client.GetEvals().ToList();

            foreach(var eval in evalList) {
                Console.WriteLine(eval.Id);
            }

            client.Close();
        }

I can access the service on my local IIS as well.

1
Can you post your client code as well? Just the part that connects to the service.Jude Fisher
Can you confirm if your service activates successfully? Try browsing to URL localhost/WebEvalService and see help page.Praburaj

1 Answers

0
votes

There was a problem with service endpoint declaration in your web.config file. Try this,

  <service name="EvalServiceLibrary.EvalService">

    <!-- This endpoint is exposed at the http://localhost/EvalServiceLibrary/EvalService.svc-->
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" name="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />

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

Basically,

  1. Your endpoint address is invalid. Infact you no need to specify.

  2. Add MexEndpoint.