C#代码直接调用WCF服务

来源:互联网 发布:windows 10没远程桌面 编辑:程序博客网 时间:2024/06/06 07:29
public string GetResult(string inputmodel)       {           string modelstring = null;           try           {               string Address = System.Configuration.ConfigurationManager.AppSettings["O2OServiceUrl"].ToString();               System.ServiceModel.WebHttpBinding Binding = new System.ServiceModel.WebHttpBinding();               System.ServiceModel.Description.WebHttpBehavior behavior = new System.ServiceModel.Description.WebHttpBehavior();               ChannelFactory<JHDWCF.Contract.Sys.ISysInput> channelFactory = new ChannelFactory<JHDWCF.Contract.Sys.ISysInput>(Binding, Address);               channelFactory.Endpoint.Behaviors.Add(behavior);               JHDWCF.Contract.Sys.ISysInput method = channelFactory.CreateChannel();               JHDWCF.Model.InputPars pars = new JHDWCF.Model.InputPars();               pars.Parameter = inputmodel;               modelstring = method.HttpService(pars);           }           catch (Exception ex)           {               throw new Exception(ex.Message);           }           return modelstring;       }

今天折腾了1小时才实现这个方法。记录在此。避免下次再折腾。
0 0