1

我正在使用 WCF 服务,其 wsdl 未在网站上发布。此后,该服务的开发人员给了我 wsdl 文件以从中生成代理类。

我已经使用 VS2010 svcutil.exe 命令成功生成了文件。我将文件包含在我正在处理的项目中,但是,在调用 web 服务时,没有从代理类到 web 服务主机的请求,正如我用来检查传出请求和响应的第三方数据包嗅探器所证明的那样.

我只是通过静态信息发送

我是 WCF 服务的新手,所以请告知是否有我需要添加的部分。

Imports System.Data
Imports System.ServiceModel
Imports System.Web.UI.Page
Imports System.Math 
Public Class webservicetest
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim Song As New request
    Try
        Song.songname() = "TakeMeHome"
        Song.trackNumber() = Convert.ToInt32("1")
        Song.requestNumber() = Convert.ToInt32("5689")
        Song.language() = "english"
        Song.albumtitle() = "GetMeThere"
        Song.totalAlbums() = Convert.ToDecimal("35")

        Dim songresponse As New responce

        Label1.Text = songresponse.errorMessage()
        Label2.Text = songresponse.requestDateTime()
        Label3.Text = songresponse.requestNumber()
        Label4.Text = songresponse.status()
    Finally
    End Try
End Sub

End Class

app.config 的一部分

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_Songinformation" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Transport">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="urlWherewebserviceIsDeployed"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Songinformation"
            contract="Songdata" name="BasicHttpBinding_Songdata" />
    </client>
</system.serviceModel>

代理类的一部分

Imports System.Runtime.Serialization
<Assembly: System.Runtime.Serialization.ContractNamespaceAttribute("http://ucizi.music/DataContracts", ClrNamespace:="ucizi.music.DataContracts")>

Namespace ucizi.music.DataContracts

<System.Diagnostics.DebuggerStepThroughAttribute(), _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"), _
     System.Runtime.Serialization.DataContractAttribute(Name:="Request", [Namespace]:="http://ucizi.Music/DataContracts")> _
    Partial Public Class Request
    Inherits Object
    Implements System.Runtime.Serialization.IExtensibleDataObject
    Private extensionDataField As System.Runtime.Serialization.ExtensionDataObject

    Private albumtitle As String

    Private songname As String

    Private trackNumber As Integer

    Private language As String

    Private requestNumber As UInteger

    Private totalAlbums As Integer


    Public Property ExtensionData() As       System.Runtime.Serialization.ExtensionDataObject Implements      System.Runtime.Serialization.IExtensibleDataObject.ExtensionData
        Get
            Return Me.extensionDataField
        End Get
        Set(ByVal value As System.Runtime.Serialization.ExtensionDataObject)
            Me.extensionDataField = Value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True)> _
    Public Property albumtitle() As String
        Get
            Return Me.albumtitlebox
        End Get
        Set(ByVal value As String)
            Me.albumtitlebox = Value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True, Order:=2)> _
    Public Property songname() As String
        Get
            Return Me.songnamebox
        End Get
        Set(ByVal value As String)
            Me.songnamebox = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True, Order:=3)> _
    Public Property tracknumber() As Integer
        Get
            Return Me.tracknumberbox
        End Get
        Set(ByVal value As Integer)
            Me.tracknumberbox = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True, Order:=4)> _
    Public Property language() As String
        Get
            Return Me.languagebox
        End Get
        Set(ByVal value As String)
            Me.languagebox = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True, Order:=5)> _
    Public Property requestnumber() As UInteger
        Get
            Return Me.requestnumberbox
        End Get
        Set(ByVal value As UInteger)
            Me.requestnumberbox = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute(IsRequired:=True, Order:=6)> _
    Public Property totalAlbums() As Integer
        Get
            Return Me.totalAlbumsbox
        End Get
        Set(ByVal value As Integer)
            Me.totalAlbumsbox = value
        End Set
    End Property
End Class

'rest of codes
End Namespace

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _
 System.ServiceModel.ServiceContractAttribute([Namespace]:="http://ucizi.music/ServiceContracts", ConfigurationName:="MusicServiceContract")> _
Public Interface MusicServiceContract

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message SubmitRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "ayment", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "aymentResponse"), _
  System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "aymentGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function SubmitPayment(ByVal request As SubmitRequest) As SubmitPaymentResponse

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message SubmitReversalRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitR" & _
    "eversal", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitR" & _
    "eversalResponse"), _
  System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitR" & _
    "eversalGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function SubmitReversal(ByVal request As SubmitReversalRequest) As SubmitReversalResponse

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message GetPaymentConfRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/Payment" & _
    "Confirmation", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/Payment" & _
    "ConfirmationResponse"), _
  System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/Payment" & _
    "ConfirmationGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function PaymentConfirmation(ByVal request As GetPaymentConfRequest) As GetPaymentConfResponse

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message GetAvailableMOPRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetAvai" & _
    "lableMethodOfPayments", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetAvai" & _
    "lableMethodOfPaymentsResponse"), _
     System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetAvai" & _
    "lableMethodOfPaymentsGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function GetAvailableMethodOfPayments(ByVal request As GetAvailableMOPRequest) As GetAvailableMOPResponse

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message GetTransactionHistoryRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetTran" & _
    "sactionHistory", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetTran" & _
    "sactionHistoryResponse"), _
 System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/GetTran" & _
    "sactionHistoryGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function GetTransactionHistory(ByVal request As GetTransactionHistoryRequest) As GetTransactionHistoryResponse

'CODEGEN: Generating message contract since the wrapper namespace (http://ucizi.music/MessageContracts) of message SubmitSmartCardRequest does not match the default value (http://ucizi.music/ServiceContracts)
<System.ServiceModel.OperationContractAttribute(Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "aymentUsingSmartCard", ReplyAction:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "aymentUsingSmartCardResponse"), _
 System.ServiceModel.FaultContractAttribute(GetType(ucizi.music.DataContracts.GeneralFaultContract), Action:="http://ucizi.music/ServiceContracts/MusicServiceContract/SubmitP" & _
    "aymentUsingSmartCardGeneralFaultContractFault", Name:="GeneralFaultContract", [Namespace]:="http://ucizi.music/DataContracts")> _
Function SubmitPaymentUsingSmartCard(ByVal request As SubmitSmartCardRequest) As SubmitPaymentResponse
End Interface

<System.Diagnostics.DebuggerStepThroughAttribute(), _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _
  System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced), _
 System.ServiceModel.MessageContractAttribute(WrapperName:="SubmitRequest", WrapperNamespace:="http://ucizi.music/MessageContracts", IsWrapped:=True)> _
    Partial Public Class SubmitRequest

    <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://ucizi.music  /ServiceContracts", Order:=0)>   _
   Public Request As ucizi.music.DataContracts.Request

Public Sub New()
    MyBase.New()
End Sub

Public Sub New(ByVal Request As ucizi.music.DataContracts.Request)
    MyBase.New()
    Me.Request = Request
End Sub
End Class

<System.Diagnostics.DebuggerStepThroughAttribute(), _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
Partial Public Class MusicServiceContractsClient
Inherits System.ServiceModel.ClientBase(Of MusicServiceContracts)
Implements MusicServiceContracts

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

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _
    Function MusicServiceContract_SubmitRequest(ByVal request As SubmitMusicRequest) As SubmitMusicResponse Implements MusicServiceContracts.SubmitMusic
    Return MyBase.Channel.SubmitMusic(request)
End Function

Public Function SubmitMusic(ByVal PaymentRequest As multichoice.paymentservice.DataContracts.PaymentRequest) As multichoice.paymentservice.DataContracts.TransactionResponse
    Dim inValue As SubmitMusicRequest = New SubmitMusicRequest()
    inValue.PaymentRequest = PaymentRequest
    Dim retVal As SubmitMusicResponse = CType(Me, MusicServiceContracts).SubmitMusic(inValue)
    Return retVal.PaymentResponse
End Function

End Class
4

1 回答 1

1

您目前正在new回复。您需要创建一个服务客户端并使用它来调用服务以获取您的响应。

我是一名 C# 开发人员,但我想像这样:

Dim client as New MusicServiceContractsClient
Dim songresponse = client.SubmitMusic(request)
于 2013-04-11T18:39:08.230 回答