2011-05-06 36 views
0

我想這一個...但它不工作..有誰知道如何使用渠道工廠的客戶端訪問wcf服務?

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 
+0

你是什麼意思是「不工作」?請添加錯誤信息 – jeroenh 2011-05-06 06:02:31

回答

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 
+0

Siya:您能分享可以在Excel VBA中工作的VB代碼嗎? – 2014-06-10 11:38:35

相關問題