我如何调用WCF服务 [英] How can i call a WCF Service

查看:80
本文介绍了我如何调用WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每一个

i有一个wcf服务(Chat_Server)

我用命令做了一个web.config和callback类:

Hi every one
i have a wcf service (Chat_Server)
and i made a web.config and callback class with command :

svcutil.exe http://localhost:1462/Service_Chat.svc?wsdl



这是我的配置:


this is my config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IService_Chat">
          <reliableSession inactivityTimeout="00:01:00" />
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:1462/Service_Chat.svc" binding="wsDualHttpBinding"

          bindingConfiguration="WSDualHttpBinding_IService_Chat" contract="IService_Chat"

          name="WSDualHttpBinding_IService_Chat" />
    </client>
  </system.serviceModel>
</configuration>





这是我的班级(Service_ChatClient)名称:





and this is my class with (Service_ChatClient) name :

'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.17929
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On



<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _
 System.ServiceModel.ServiceContractAttribute(ConfigurationName:="IService_Chat", CallbackContract:=GetType(IService_ChatCallback), SessionMode:=System.ServiceModel.SessionMode.Required)> _
Public Interface IService_Chat

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/Connect")> _
    Sub Connect(ByVal Username As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/SendMessage")> _
    Sub SendMessage(ByVal Username As String, ByVal message As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/OnMessage")> _
    Sub OnMessage(ByVal message As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/Disconnect")> _
    Sub Disconnect(ByVal Username As String)
End Interface

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
Public Interface IService_ChatCallback

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/Connect")> _
    Sub Connect(ByVal Username As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/SendMessage")> _
    Sub SendMessage(ByVal Username As String, ByVal message As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/OnMessage")> _
    Sub OnMessage(ByVal message As String)

    <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService_Chat/Disconnect")> _
    Sub Disconnect(ByVal Username As String)
End Interface

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
Public Interface IService_ChatChannel
    Inherits IService_Chat, System.ServiceModel.IClientChannel
End Interface

<System.Diagnostics.DebuggerStepThroughAttribute(), _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
Partial Public Class Service_ChatClient
    Inherits System.ServiceModel.DuplexClientBase(Of IService_Chat)
    Implements IService_Chat

    Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext)
        MyBase.New(callbackInstance)
    End Sub

    Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String)
        MyBase.New(callbackInstance, endpointConfigurationName)
    End Sub

    Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
        MyBase.New(callbackInstance, endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(callbackInstance, endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(callbackInstance, binding, remoteAddress)
    End Sub

    Public Sub Connect(ByVal Username As String) Implements IService_Chat.Connect
        MyBase.Channel.Connect(Username)
    End Sub

    Public Sub SendMessage(ByVal Username As String, ByVal message As String) Implements IService_Chat.SendMessage
        MyBase.Channel.SendMessage(Username, message)
    End Sub

    Public Sub OnMessage(ByVal message As String) Implements IService_Chat.OnMessage
        MyBase.Channel.OnMessage(message)
    End Sub

    Public Sub Disconnect(ByVal Username As String) Implements IService_Chat.Disconnect
        MyBase.Channel.Disconnect(Username)
    End Sub
End Class





现在我不知道如何创建我的新类(Service_ChatClient)并将其称为方法?

谢谢。



Now i don't know how can i make a new class of my ( Service_ChatClient ) and call it methods?
thank you.

推荐答案

你可以创建你生成的对象代理类并调用你想要使用的方法。
You Can just create object proxy class you have generated and call the methods you want to use.


你好,新浪,



首先你必须创建如下的客户对象 -

Hi Sina,

First you have to create client object like below-
Dim cnt As New ServiceReference1.Service1Client





然后使用下面的客户端对象消耗服务方法 -



and then consume service method by using client object like below-

cnt.YourServiceMethod(param1,param2)



就像普通的本地方法一样。


just as normal local method.


检查这些链接



< a href =http://msdn.microsoft.com/en-us/library/vstudio/ms730059(v=vs.100).aspx> http://msdn.microsoft.com/en-us/library/ vstudio / ms730059(v = vs.100).aspx [ ^ ]



http://msdn.microsoft.com/en-us/library/ms734691 (v = vs.110).aspx [ ^ ]



http://msdn.microsoft.com/en-us/library/bb386386.aspx [ ^ ]
Check these Links

http://msdn.microsoft.com/en-us/library/vstudio/ms730059(v=vs.100).aspx[^]

http://msdn.microsoft.com/en-us/library/ms734691(v=vs.110).aspx[^]

http://msdn.microsoft.com/en-us/library/bb386386.aspx[^]


这篇关于我如何调用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆