Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 某些计算机上的WCF编译错误_C#_Wcf_Somee - Fatal编程技术网

C# 某些计算机上的WCF编译错误

C# 某些计算机上的WCF编译错误,c#,wcf,somee,C#,Wcf,Somee,我是WCF的新手,我需要在somee上部署一点服务,但我遇到了这个错误 我在somee上有两个文件: web.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="Microsoft.ServiceModel.Samples.Calcul

我是WCF的新手,我需要在somee上部署一点服务,但我遇到了这个错误

我在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>

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

使用制度;
使用System.ServiceModel;
命名空间Microsoft.ServiceModel.Samples
{
[服务合同]
公共接口计算器
{
[经营合同]
双加(双n1,双n2);
[经营合同]
双减法(双n1,双n2);
[经营合同]
双乘(双n1,双n2);
[经营合同]
双除法(双n1,双n2);
}
公共类计算器服务:ICalculator
{
公共双加(双n1,双n2)
{
返回n1+n2;
}
公共双减法(双n1,双n2)
{
返回n1-n2;
}
公共双乘(双n1,双n2)
{
返回n1*n2;
}
公共双除法(双n1,双n2)
{
返回n1/n2;
}
}
}

请告诉我我做错了什么?看来somee没有访问某个文件的权限。我从这里获取了这段代码

我建议您使用Visual Studio的新项目模板来完成这项工作。转到新建项目->WCF->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" %>
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;
        }
    }
}
<?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>
web.config:

<%@ ServiceHost Language="C#" Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService" CodeBehind="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;
        }
    }
}
<?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>

没有。。。它也不起作用。出现此错误:找不到作为ServiceHost指令中的服务属性值提供的或配置元素system.ServiceModel/serviceHostingEnvironment/serviceActivations中提供的类型“Microsoft.ServiceModel.Samples.CalculatorService”。