0

我有一个WCF 服务应用程序项目、一个类库项目(充当服务和客户端之间的代理)和一个Asp.net Web 项目

现在在WCF 服务应用程序项目中,我有方法 GetData(int) [默认的]

public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }        
    }

我编译了 WCF 服务项目,发现它工作正常,因此将其添加为对类库项目的服务引用。并编写了一个方法来从服务中获取值

public string GetResult(int number)
        {
            string result = "";
            try
            {
                Service1Client sc = new Service1Client();
                result = sc.GetData(number); 
            }
            catch (Exception ex)
            {
               var message = ex.Message;
            }
            return result;
        }

现在正在从 Web 应用程序调用此方法。在运行时我遇到异常

在 ServiceModel 客户端配置部分中找不到引用合同“ServiceReference1.IService1”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

错误发生在 Service1Client sc = new Service1Client();

所有的配置文件都准备好了....我应该使用 SVC util 创建代理吗?

我错过了什么?

4

1 回答 1

1

你确定你在 web.config 中有适当的 wcf 配置吗?看来你没有。

于 2012-01-22T08:26:42.480 回答