【问题标题】:Does anyone know how to access the wcf service by a client using channel factory?有谁知道客户端如何使用通道工厂访问 wcf 服务?
【发布时间】:2011-05-06 05:29:24
【问题描述】:

我试过这个...但它不起作用..

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim channel As New ChannelFactory(Of IWidgetServiceProxy)(
                                 New WSHttpBinding(), 
                                 "http://localhost:4676/WidgetServiceProxy.svc")
     Dim client As IWidgetServiceProxy = channel.CreateChannel()

     Dim str As String = client.GetWidgetInstanceTitle()


     Response.Write(str)
     'ProcessStatuses(resp)

End Sub

【问题讨论】:

  • “不工作”是什么意思?请添加错误消息

标签: vb.net wcf channelfactory


【解决方案1】:

这段代码对我有用:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)        Handles Me.Load

    Dim intr As IWc fInterface
    Dim chnl As ChannelFactory(Of IWcfInterface) = New ChannelFactory(Of IWcfInterface)(New WebHttpBinding(), "http://localhost:49821/Service1.svc")
    chnl.Endpoint.Behaviors.Add(New WebHttpBehavior())
    intr = chnl.CreateChannel()

    Using New OperationContextScope(DirectCast(intr, IContextChannel))

        Dim rspnse As List(Of UserDetails) = intr.GetDataFromDB()
        GridView1.DataSource = rspnse
        GridView1.DataBind()
    End Using
End Sub

【讨论】:

  • Siya : 可以分享一下可以在 Excel VBA 中运行的 VB 代码吗?
猜你喜欢
  • 2011-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 2015-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多