asp.net – 如何在DLL中添加Web服务引用
发布时间:2020-05-25 04:44:11 所属栏目:asp.Net 来源:互联网
导读:我正在创建一个引用Web服务的DLL(我没有选择这样做)但我必须向使用DLL的项目添加Web服务引用才能使用它. 例如,我有一个名为API.DLL的DLL,它调用一个名为WebService.svc的Web服务,我想在一个名为WinForm的项目中使用它.首先,我必须在API.DLL中向WebService.svc
|
我正在创建一个引用Web服务的DLL(我没有选择这样做)但我必须向使用DLL的项目添加Web服务引用才能使用它. 例如,我有一个名为API.DLL的DLL,它调用一个名为WebService.svc的Web服务,我想在一个名为WinForm的项目中使用它.首先,我必须在API.DLL中向WebService.svc添加“服务引用”.然后,我将一个引用API.DLL添加到WinForm但它不起作用,除非我还在WinForm中添加对WebService.svc的服务引用. 我该怎么做才能避免最后一步? 解决方法您的第一步是向自己证明这是可能的,然后调整您的项目.你可以下载runnable解决方案here. 我刚刚完成了这些步骤并列举了我的行动以产生你想要的结果.
Create a web app project (an thus a solution) named 'ReferencedWebService'
Add a web service,just leave the default name and implementation
Add a class library named 'ReferencedWebserviceAPI'
Add Service Reference
>Advanced
>Add Web Reference>Web services in this solution
>WebService1
>Add reference leaving name as 'localhost'
Add a console application project named 'ReferencedWebserviceClient'
To ReferencedWebserviceClient:
Add Reference
>Projects
>ReferencedWebserviceAPI
Add Reference
>.Net
>System.Web.Services
In Program.cs replace Main:
static void Main(string[] args)
{
var svc = new ReferencedWebserviceAPI.localhost.WebService1();
var result = svc.HelloWorld();
Console.WriteLine(result);
Console.ReadLine();
}
Set ReferencedWebserviceClient as startup project and run.
Ok,this is simplest scenario. One issue you will have to deal with is that the default Service URL is hardcoded in the .dll,and it is set to a ported address on your dev machine.
You will want to add a configuration parameter to your client project. The simplest and most portable way is to use an appSetting.
To ReferencedWebserviceClient:
Add Item
>Application Configuration File
Replace contents of App.Config with this,of course replace the value with the appropriate value on your machine.
Add Reference
>.Net
>System.Configuration
Now replace Main with this:
static void Main(string[] args)
{
var svc = new ReferencedWebserviceAPI.localhost.WebService1
{
Url = ConfigurationManager.AppSettings["serviceUrl"]
};
var result = svc.HelloWorld();
Console.WriteLine(result);
Console.ReadLine();
}
这是在可再发行的.dll中嵌入服务的基线. 尝试将此模型应用于您当前的项目,看看它是如何为您工作的. 如果你仍然有问题,你肯定有一个参考问题,应该从这个角度开始看. 希望这可以帮助 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET FileUpload:如何在选择文件后自动回复?
- asp.net-mvc – 使用mvc-mini-profiler
- asp.net – FormsAuthentication.SetAuthCookie()是否创建一
- asp.net-mvc – ASP.NET MVC使用相同的控制器分离移动视图
- asp.net core 实现一个简单的仓储的方法
- ASP.NET编译器抱怨MiniProfiler不匹配的框架版本
- asp.net – 我可以在一个Web项目中拥有多个web.config文件吗
- asp.net-mvc – 如何设置TextBox的空字符串而不是null的默认
- asp.net – 使用jQuery以编程方式触发JavaScript中的事件
- asp.net-mvc – 如何将URL参数绑定到具有不同名称的模型属性
推荐文章
站长推荐
- asp.net – 是否有可能检测到移动浏览器的GPS位置
- asp.net – 需要安装Dnx Runtime软件包 有关详细
- asp.net-mvc – 创建自定义RouteBase类
- asp.net-mvc – Mocking HttpPostedFileBase和In
- asp.net – 如何向python中的.aspx页面提交查询
- Asp.net MVC json还是Json.net?
- ASP.NET 2.0 JQuery AJAX登录
- asp.net – 经过身份验证的服务不支持跨域javasc
- asp.net – System.Net.Mail新MailMessage随机发
- asp.net-mvc – 为什么ASP.NET在静态图像请求上形
热点阅读
