有没有人知道如何使用渠道工厂的客户端访问wcf服务?

时间:2011-05-06 05:29:25

标签: vb.net wcf channelfactory

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

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

1 个答案:

答案 0 :(得分:0)

此代码对我有用:

   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
相关问题