某人的WCF编译错误

时间:2017-02-21 22:39:09

标签: c# wcf somee

我在WCF中是全新的,我需要在somee上部署一些服务,但是我收到此错误enter image description here

我有两个文件:

的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>

和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;
        }
    }
}

请告诉我,我做错了什么?看起来somee无法访问某些文件。我从这里https://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx

获取了这段代码

1 个答案:

答案 0 :(得分:0)

我建议您使用Visual Studio的新项目模板来执行此操作。转到新项目 - &gt; WCF - &gt; WCF服务应用程序。

话虽如此,你应该有3个文件:Service.svc,Service.svc.cs和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>