0

I'm completely new in WCF nd I need to deploy a little service on somee, but I get this errorenter image description here

I have two files on somee:

web.config

<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
  <system.serviceModel>  
    <services>  
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">   
        <endpoint address=""  
                  binding="wsHttpBinding"  
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />  
        <endpoint address="mex"  
                  binding="mexHttpBinding"  
                  contract="IMetadataExchange" />  
      </service>  
    </services>  
  </system.serviceModel>  
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

and service.svc

<%@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService"%> 

using System;
using System.ServiceModel;

namespace Microsoft.ServiceModel.Samples
{

    [ServiceContract]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
    }


    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            return n1 + n2;
        }
        public double Subtract(double n1, double n2)
        {
            return n1 - n2;
        }
        public double Multiply(double n1, double n2)
        {
            return n1 * n2;
        }
        public double Divide(double n1, double n2)
        {
            return n1 / n2;
        }
    }
}

Please tell me what am I doing wrong? Looks like somee doesn't have an access to some file. I took this code from here https://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx

1 Answers1

0

I suggest you use Visual Studio's New Project templates to do this. Go to New Project -> WCF -> WCF Service Application.

Having said that, you should have 3 files: Service.svc, Service.svc.cs, and Web.config:

service.svc:

<%@ ServiceHost Language="C#" Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService" CodeBehind="Service.svc.cs" %>

service.svc.cs:

using System;
using System.ServiceModel;

namespace Microsoft.ServiceModel.Samples
{

    [ServiceContract]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
    }


    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            return n1 + n2;
        }
        public double Subtract(double n1, double n2)
        {
            return n1 - n2;
        }
        public double Multiply(double n1, double n2)
        {
            return n1 * n2;
        }
        public double Divide(double n1, double n2)
        {
            return n1 / n2;
        }
    }
}

web.config:

<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
  <system.serviceModel>  
    <services>  
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">   
        <endpoint address=""  
                  binding="wsHttpBinding"  
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />  
        <endpoint address="mex"  
                  binding="mexHttpBinding"  
                  contract="IMetadataExchange" />  
      </service>  
    </services>  
  </system.serviceModel>  
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>
Jorge Del Conde
  • 265
  • 1
  • 4
  • Nope... It didn't work either. Got this error: The type 'Microsoft.ServiceModel.Samples.CalculatorService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found. – Vitalii Paprotskyi Feb 22 '17 at 07:02