我正在尝试调用未在其网站上发布 wsdl 的 Web 服务。该服务的开发人员给了我 wsdl 文件以从中生成代理类。
我已经使用 VS2010 svcutil.exe 命令成功生成了文件。我将文件包含在我正在处理的项目中,但是,在调用 web 服务时,没有请求发出,正如我用来检查传出请求和响应的 fiddler2 所证明的那样。
在下面的文件中,我将从数据库中获取数据,但出于测试原因,我只是通过静态信息发送。
Imports System.Data
Imports System.ServiceModel
Imports System.Web.UI.Page
Imports System.Math
Imports MusicShop.Album.Song
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() = "TameMeHome"
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>
==代理类文件的一部分==
Option Strict Off
Option Explicit On
Imports System.Runtime.Serialization
<Assembly: System.Runtime.Serialization.ContractNamespaceAttribute("URLForDataContract", ClrNamespace:="New MusicShop.Album.Song")>
Namespace New MusicShop.Album.Song
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"), _
System.Runtime.Serialization.DataContractAttribute(Name:="Request", [Namespace]:="URLforDataContract")> _
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.albumtitle
End Get
Set(ByVal value As String)
Me.albumtitlebox = Value
End Set
End Property