尝试访问项目类型为“WCF 服务应用程序”的 WCF 服务中的方法时出错

发布于 2024-12-28 10:58:02 字数 1174 浏览 4 评论 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();< /code>

所有配置文件都已就位...我是否必须使用 SVC util 创建代理?

我缺少什么?

I have a WCF Service application project , a class library project(acts as a proxy betwen the service and the client) and a Asp.net web project.

Now in the WCF Service application project, I have the method GetData(int) [the default one]

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

I complied the WCF service project and found it working and henceforth added that as service reference to the Class library project. And written a method as under to fetch the value from the service

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

Now this method is being invoked from the Web application. At runtime I am getting an exception

Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

The error is happening at Service1Client sc = new Service1Client();

All the config files are in place....Should I have to create the proxy using SVC util?

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念﹏祤嫣 2025-01-04 10:58:02

您确定在 web.config 中放置了适当的 wcf 配置吗?看来你不这么认为。

Are you sure you have apropriate configuration for wcf placed in web.config? It seems you don't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文