2014-04-14 3 views
1

VB에서 쓰는 양식에 대한 새로운 서비스 참조를 만드는 법을 배우고 있습니다. 내가 그렇게 같은 기준 입력 할 때 :작업은 서비스 참조 번호가 아닙니다.

ServiceReference.Operation 

을 나는 " '조작' '서비스 참조'의 멤버가 아닙니다"라는 오류가 내가 잘못 뭐하는 거지? 다음은 코드입니다. 서비스

Public Class Service 
    Implements IService 

    Public Sub New() 
    End Sub 

    Public Function GetChargeAmount(ByRef d As Double) As Double Implements IService.GetChargeAmount 
     Return 200.0 * (d * 60) 
    End Function 

End Class 

인터페이스

<ServiceContract()> 
Public Interface IService 

    <OperationContract()> 
    Function GetChargeAmount(ByRef d As Double) As Double 

End Interface 

<DataContract()> 
Public Class CompositeType 

    <DataMember()> 
    Public Property BoolValue() As Boolean 
    <DataMember()> 
    Public Property StringValue() As String 

End Class 

호출 코드는 대신 서비스 참조의 네임 스페이스를 사용하여 서비스 작업에 대한 메소드를 호출하려고하는 것 같습니다

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click 
     If (tbGroup.Text = "" Or tbMinutes.Text = "") Then 
      MessageBox.Show("Please fill out all necesary information") 
      ClearText() 
     Else 
      Dim dMoney As Double = 0.0 
      dMoney = ChargeReference.GetChargeAmount(Double.Parse(tbMinutes.Text)) 
      tbTotalCharge.Text = dMoney.ToString("C") 



    End If 
     End Sub 
+1

서식을 고정했습니다. – Jbf1001

+1

서비스 참조 인 경우 생성 된 "클라이언트"클래스를 사용해야합니다. 예를 들면 다음과 같습니다 :'Using myservice = new ServiceClient()'. – Styxxy

답변

0

ServiceClient 클래스 - 예 : ChargeReference.ServiceClient.GetChargeAmount이 아닌 ChargeReference.GetChargeAmount

대신을 시도해보십시오

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click 
    If (tbGroup.Text = "" Or tbMinutes.Text = "") Then 
     MessageBox.Show("Please fill out all necessary information") 
     ClearText() 
    Else 
     Dim dMoney As Double = 0.0 
     Dim serviceClient = New ChargeReference.ServiceClient() ' Instantiate the service client. 
     dMoney = serviceClient.GetChargeAmount(Double.Parse(tbMinutes.Text)) 
     tbTotalCharge.Text = dMoney.ToString("C") 
    End If 
End Sub 

당신이 ChargeReference을 위해 생성 된 코드를 보면, 차이가 꽤 분명하다. 추가 명확성을 위해 몇 가지 의견을 추가했습니다.

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

Option Strict On 
Option Explicit On 


' 
' NOTE: namespace named the same as the service reference in Solution Explorer 
' 
Namespace ChargeReference 

    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _ 
    System.ServiceModel.ServiceContractAttribute(ConfigurationName:="ChargeReference.IService")> _ 
    Public Interface IService 

     <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IService/GetChargeAmount", ReplyAction:="http://tempuri.org/IService/GetChargeAmountResponse")> _ 
     Function GetChargeAmount(ByRef d As Double) As Double 
    End Interface 

    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _ 
    Public Interface IServiceChannel 
     Inherits ChargeReference.IService, System.ServiceModel.IClientChannel 
    End Interface 

    ' 
    ' NOTE: generated ServiceClient class through which to use the service reference 
    ' 
    <System.Diagnostics.DebuggerStepThroughAttribute(), _ 
    System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _ 
    Partial Public Class ServiceClient 
     Inherits System.ServiceModel.ClientBase(Of ChargeReference.IService) 
     Implements ChargeReference.IService 

     Public Sub New() 
      MyBase.New 
     End Sub 

     Public Sub New(ByVal endpointConfigurationName As String) 
      MyBase.New(endpointConfigurationName) 
     End Sub 

     Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As String) 
      MyBase.New(endpointConfigurationName, remoteAddress) 
     End Sub 

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

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

     ' 
     ' NOTE: generated service-client (instance) method through which to call the service operation 
     ' 
     Public Function GetChargeAmount(ByRef d As Double) As Double Implements ChargeReference.IService.GetChargeAmount 
      Return MyBase.Channel.GetChargeAmount(d) 
     End Function 
    End Class 
End Namespace 
+1

너 락맨. 나는 나의 손이 저것을 위해 떨어질 때까지 Googled했다. 나는 보통 VB에서 일하므로 자바 스크립트를 사용한다. – Jbf1001

+0

감사합니다. 도와 드리겠습니다. 기꺼이 지금 당신을 위해 일하고 있습니다. [ "아니, 너 락이야, 매그넘을 언제 우리에게 떨어 뜨릴거야, 친구?"] (http://www.imdb.com/title/tt0196229/quotes?item=qt0375870) : D – J0e3gan