【问题标题】:WCF Compilation error on somee某些人的WCF编译错误
【发布时间】:2017-02-21 22:39:08
【问题描述】:

我是 WCF 的新手,需要在某些人上部署一些服务,但我收到此错误

我在某人上有两个文件:

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

请告诉我我做错了什么?看起来有些人无权访问某些文件。我从这里获取了这段代码https://msdn.microsoft.com/en-us/library/ms733766(v=vs.110).aspx

【问题讨论】:

    标签: c# wcf somee


    【解决方案1】:

    我建议您使用 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" %>
    

    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>
    

    【讨论】:

    • 不...它也没有用。收到此错误:找不到类型“Microsoft.ServiceModel.Samples.CalculatorService”,作为 ServiceHost 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2018-06-29
    相关资源
    最近更新 更多