C#函数封装问题

风一样的大叔 2012-11-08 04:49:54
  
//这四句在很多地方都用到了
SMC.Binding binding = WcfServiceClient.CreateDefaultBinding();
string remoteAddress = WcfServiceClient.EndpointAddress.Uri.ToString();
EndpointAddress endpoint = new EndpointAddress(remoteAddress);
WcfServiceClient client = new WcfServiceClient(binding, endpoint);

//后面是调用前面
DataTable myDataTable = new DataTable();
myDataTable = client.GetLocInfo(scanData.Text);

//现在我想把前面四句封装起来
//但由于 WcfServiceClient client = new WcfServiceClient(binding, endpoint);
//不是一个值类型,请问怎么封装啊?
...全文
151 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
风一样的大叔 2012-11-08
  • 打赏
  • 举报
回复
引用 3 楼 caozhy 的回复:
选中这四行,点右键,重构,提取方法。
好吧,刚才我是把这个
引用 1 楼 bdmh 的回复:
C# code123456789public WcfServiceClient GetClient(){ SMC.Binding binding = WcfServiceClient.CreateDefaultBinding(); string remoteAddress = WcfServiceClient.EndpointAddress.U……
移到其他文件中取了
引用 3 楼 caozhy 的回复:
选中这四行,点右键,重构,提取方法。
果然很强大 谢谢二位版主
threenewbee 2012-11-08
  • 打赏
  • 举报
回复
选中这四行,点右键,重构,提取方法。
风一样的大叔 2012-11-08
  • 打赏
  • 举报
回复
引用 1 楼 bdmh 的回复:
C# code123456789public WcfServiceClient GetClient(){ SMC.Binding binding = WcfServiceClient.CreateDefaultBinding(); string remoteAddress = WcfServiceClient.EndpointAddress.U……
EndpointAddress endpoint = new EndpointAddress(remoteAddress);报以下错误 错误 2 “WcfServiceClient.EndpointAddress”是“字段”,但此处被当做“类型”来使用 C:\Documents and Settings\Administrator\桌面\v2.6\Windows CE\Samples VS2008\C#\CS_Barcode2ControlSample1\WcfService\WcfService.cs 151 9 WirelessRouteSystem
bdmh 2012-11-08
  • 打赏
  • 举报
回复

public WcfServiceClient GetClient()
{
        SMC.Binding binding = WcfServiceClient.CreateDefaultBinding();
        string remoteAddress = WcfServiceClient.EndpointAddress.Uri.ToString();
        EndpointAddress endpoint = new EndpointAddress(remoteAddress);
        WcfServiceClient client = new WcfServiceClient(binding, endpoint);
        return client;
}

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧