通过.net3.5 VS 2008中的类库使用Web服务 [英] consume webservice through class library in .net3.5 VS 2008

查看:63
本文介绍了通过.net3.5 VS 2008中的类库使用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务,可以直接从我的Web表单访问它.我在wesite中使用了服务参考,并在我的网络表单上使用了一个serviceclient,效果很好.

现在,我从网站上删除了服务引用,并创建了一个类库,该类库使用类中的服务引用和服务客户​​端以相同的方式使用此Web服务.

现在,当我尝试使用该类库时,它给我一个错误,即在类库中找不到合同的默认终结点.它创建服务客户端,但在执行serviceclient.method-name时失败.我在对象浏览器中检查了一下,在类库下有一个服务节点,在该节点下我找到了服务客户端,并且服务客户端下的所有方法都存在.同样在调试中,我检查了服务客户端对象和serviceclient.method在监视窗口中可用,但在代码中失败.

我在我的网站上添加了该类库的参考.

我要去哪里错了? :doh:

I had a webservice which I was directly accessing from my webform. I used a service reference in my wesite and used a serviceclient on my webform which worked fine.

Now I removed the service reference from my website and created a class library Which consumes this webservice the same way using a service reference and service client in the class.

When I try to use this class library now it gives me an error that no default endpoint found for the contract in class library. It creates the service client but fails when I do serviceclient.method-name. I checked in the object browser and under the classlibrary there''s a node for service and under it I found service client and all the methods under service client are present. Also putting into debug I checked the service client object and serviceclient.method was available in watch window but fails in code.

I''ve added a reference of this class library in my website.

Where am i going wrong? :doh:

推荐答案

最简单的方法是让您在Web项目中重新添加Web服务引用,以便将适当的配置值添加到Web中.该站点的配置文件.当网站引用类库时,该服务的web.config中的配置值也将对类库对象可用.将引用保留在两个项目中,因为这样会使生活更轻松.
The easiest way is for you to re-add the web service reference in your web project so that the appropriate configuration values are added to you web.config file for the site. When the class library is referenced by the website, the configuration values in the web.config for the service will then be available to the class library objects as well. Leave the reference in both projects as it just makes life easier.


这篇关于通过.net3.5 VS 2008中的类库使用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆