C# 在Winform中发布WebService

上传者: 41448796 | 上传时间: 2021-06-04 12:09:49 | 文件大小: 261KB | 文件类型: RAR
完整的服务端及客户端调用程序,在win7+ vs2015环境运行通过. 一、说明 1、创建winfrom应用程序;(或者是控制台项目) 2、在项目中添加一个WCF服务,并实现服务; 3、在需要启动WebService服务的地方启动该服务即可; 二、代码如下: 1、新建一个WCF服务——定义服务接口    [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]     public interface ICalculator     {         [OperationContract]         double Add(double n1, double n2);     } 2、新建一个WCF服务——实现服务 public class CalculatorService : ICalculator     {         public double Add(double n1, double n2)         {             return n1 + n2;         }     } 3、添加完WcF服务后会在应用程序配置文件中有入下节点                             <!--TestServer.ICalculator服务定义的接口,根据自己定义进行修改-->                                                                   <baseAddresses> <!--这个是要发布的服务地址,可以进行修改-->                                   </baseAddresses>                   4、在要启动服务的地方启动服务监听   public frmMain() { InitializeComponent(); } private void frmMain_Load(object sender, EventArgs e) { try { //打开服务创建监听,并开始监听消息 ServiceHost serviceHost = new ServiceHost(typeof(Service1));//需要using System.ServiceModel; serviceHost.Open(); label1.Text = "服务启动正常"; } catch (Exception ex) { label1.Text = ex.Message; } } 5、下面可以在客户端通过上面的服务地址”http://xxx.xxx.xxx.xx:8733/test/Service1/“对服务进行调用 到这步就实现在控制台中实现webService的发布。

文件下载

资源详情

[{"title":"( 77 个子文件 261KB ) C# 在Winform中发布WebService","children":[{"title":"test","children":[{"title":".vs","children":[{"title":"YK1847","children":[{"title":"v14","children":[{"title":".suo <span style='color:#111;'> 43.00KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"PublicClass","children":[{"title":"OmronPLC.cs <span style='color:#111;'> 21.38KB </span>","children":null,"spread":false}],"spread":true},{"title":"IService1.cs <span style='color:#111;'> 448B </span>","children":null,"spread":false},{"title":"bin","children":[{"title":"Debug","children":[{"title":"YK1847-2019-03-20.rar <span style='color:#111;'> 37.69KB </span>","children":null,"spread":false},{"title":"YK1847-2019-03-18.rar <span style='color:#111;'> 37.39KB </span>","children":null,"spread":false},{"title":"YK1847.vshost.exe.manifest <span style='color:#111;'> 490B </span>","children":null,"spread":false},{"title":"YK1847.vshost.exe <span style='color:#111;'> 21.17KB </span>","children":null,"spread":false},{"title":"YK1847.exe.config <span style='color:#111;'> 1.16KB </span>","children":null,"spread":false},{"title":"YK1847-2019-03-21.rar <span style='color:#111;'> 40.90KB </span>","children":null,"spread":false},{"title":"1847接口协议说明书-nari.doc <span style='color:#111;'> 46.00KB </span>","children":null,"spread":false},{"title":"YK1847.exe <span style='color:#111;'> 25.00KB </span>","children":null,"spread":false},{"title":"YK1847.vshost.exe.config <span style='color:#111;'> 1.16KB </span>","children":null,"spread":false},{"title":"YK1847.pdb <span style='color:#111;'> 37.50KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Form1.Designer.cs <span style='color:#111;'> 3.50KB </span>","children":null,"spread":false},{"title":"Program.cs <span style='color:#111;'> 489B </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"YK1847.frmMain.resources <span style='color:#111;'> 9.22KB </span>","children":null,"spread":false},{"title":"YK1847.csproj.GenerateResource.Cache <span style='color:#111;'> 847B </span>","children":null,"spread":false},{"title":"YK1847.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.04KB </span>","children":null,"spread":false},{"title":"YK1847.csprojResolveAssemblyReference.cache <span style='color:#111;'> 1.97KB </span>","children":null,"spread":false},{"title":"YK1847.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 6.81KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferences.cache <span style='color:#111;'> 1.20KB </span>","children":null,"spread":false},{"title":"TempPE","children":[{"title":"Properties.Resources.Designer.cs.dll <span style='color:#111;'> 3.50KB </span>","children":null,"spread":false}],"spread":false},{"title":"YK1847.exe <span style='color:#111;'> 25.00KB </span>","children":null,"spread":false},{"title":"YK1847.pdb <span style='color:#111;'> 37.50KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Service1.cs <span style='color:#111;'> 503B </span>","children":null,"spread":false},{"title":"YK1847.csproj <span style='color:#111;'> 5.20KB </span>","children":null,"spread":false},{"title":"Form1.cs <span style='color:#111;'> 1.93KB </span>","children":null,"spread":false},{"title":"YK1847.csproj.user <span style='color:#111;'> 453B </span>","children":null,"spread":false},{"title":"Form1.resx <span style='color:#111;'> 18.90KB </span>","children":null,"spread":false},{"title":"YK1847.sln <span style='color:#111;'> 978B </span>","children":null,"spread":false},{"title":"App.config <span style='color:#111;'> 1.16KB </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 249B </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 1.31KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"Resources.Designer.cs <span style='color:#111;'> 2.79KB </span>","children":null,"spread":false}],"spread":false}],"spread":false},{"title":"test_Client","children":[{"title":"C_1847","children":[{"title":".vs","children":[{"title":"C_1847","children":[{"title":"v14","children":[{"title":".suo <span style='color:#111;'> 48.50KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"C_1847.sln <span style='color:#111;'> 985B </span>","children":null,"spread":false},{"title":"C_1847","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"C_1847.vshost.exe.manifest <span style='color:#111;'> 490B </span>","children":null,"spread":false},{"title":"C_1847.exe.config <span style='color:#111;'> 840B </span>","children":null,"spread":false},{"title":"C_1847.pdb <span style='color:#111;'> 23.50KB </span>","children":null,"spread":false},{"title":"C_1847.vshost.exe <span style='color:#111;'> 22.16KB </span>","children":null,"spread":false},{"title":"C_1847.exe <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false},{"title":"C_1847.vshost.exe.config <span style='color:#111;'> 840B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Form1.Designer.cs <span style='color:#111;'> 2.57KB </span>","children":null,"spread":false},{"title":"Program.cs <span style='color:#111;'> 518B </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"C_1847.csproj.GenerateResource.Cache <span style='color:#111;'> 976B </span>","children":null,"spread":false},{"title":"C_1847.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"C_1847.Form1.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"C_1847.pdb <span style='color:#111;'> 23.50KB </span>","children":null,"spread":false},{"title":"C_1847.csproj.FileListAbsolute.txt <span style='color:#111;'> 771B </span>","children":null,"spread":false},{"title":"C_1847.csprojResolveAssemblyReference.cache <span style='color:#111;'> 2.56KB </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferencesInput.cache <span style='color:#111;'> 7.87KB </span>","children":null,"spread":false},{"title":"TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"DesignTimeResolveAssemblyReferences.cache <span style='color:#111;'> 856B </span>","children":null,"spread":false},{"title":"TempPE","children":[{"title":"Service References.ServiceReference1.Reference.cs.dll <span style='color:#111;'> 4.50KB </span>","children":null,"spread":false}],"spread":false},{"title":"TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs <span style='color:#111;'> 0B </span>","children":null,"spread":false},{"title":"C_1847.exe <span style='color:#111;'> 10.00KB </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"C_1847.csproj <span style='color:#111;'> 5.16KB </span>","children":null,"spread":false},{"title":"Form1.cs <span style='color:#111;'> 974B </span>","children":null,"spread":false},{"title":"Form1.resx <span style='color:#111;'> 5.68KB </span>","children":null,"spread":false},{"title":"Service References","children":[{"title":"ServiceReference1","children":[{"title":"item1.xsd <span style='color:#111;'> 2.43KB </span>","children":null,"spread":false},{"title":"Reference.cs <span style='color:#111;'> 3.72KB </span>","children":null,"spread":false},{"title":"Reference.svcmap <span style='color:#111;'> 2.22KB </span>","children":null,"spread":false},{"title":"item.xsd <span style='color:#111;'> 1.42KB </span>","children":null,"spread":false},{"title":"configuration91.svcinfo <span style='color:#111;'> 20.88KB </span>","children":null,"spread":false},{"title":"item.disco <span style='color:#111;'> 413B </span>","children":null,"spread":false},{"title":"Service1.wsdl <span style='color:#111;'> 13.43KB </span>","children":null,"spread":false},{"title":"configuration.svcinfo <span style='color:#111;'> 1.62KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"App.config <span style='color:#111;'> 840B </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 249B </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 1.29KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.07KB </span>","children":null,"spread":false},{"title":"Resources.Designer.cs <span style='color:#111;'> 2.76KB </span>","children":null,"spread":false}],"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

  • sywnt :
    谢谢分享,初学者可以参考
    2020-08-31

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明