0

我正在构建一个 WCF 服务,该服务将部署到运行 IIS 的服务器上。我可以从当前解决方案中添加服务引用并正常使用。

如果我将服务部署到该特定机器,我是否需要将服务重新添加到使用它的应用程序中?

4

3 回答 3

3

不,您只需要更改服务 URL 以匹配另一台机器。

当您添加服务引用时会生成一个代理,该代理将对托管这些服务的所有服务器起作用——它只需要正确的 URL。

您只需要在暴露的服务发生变化时更新服务引用,例如添加新方法或更改参数。

于 2010-10-14T20:00:25.127 回答
1

不。它的工作方式是,当您将引用添加到您的项目时,它会查询给定的服务 URL,并通过 SOAP 在 XML 上创建您的特定服务的所有类和方法的列表。

这是一个 .NET 类。

如果您向服务添加了其他方法,则只需删除并阅读参考。

例如,报告服务 2005 网络服务:

添加对项目的引用,然后导入命名空间。

Imports ReportingServiceInterface.ReportingService2005_WebService

您实例化这个类的一个对象,并将 URL 传递给它。然后通过这个类的实例调用 WebService 方法。

见下文:

Public Shared Sub CreateDataSource(ByVal strPath As String, ByVal strDataSourceName As String, ByVal strConnectionString As String, ByVal strDescription As String, ByVal strUserName As String, ByVal strPassword As String)
            Dim rs As ReportingService2005 = New ReportingService2005

            rs.Credentials = ReportingServiceInterface.GetMyCredentials(strCredentialsURL)
            rs.Timeout = ReportingServiceInterface.iTimeout
            rs.Url = ReportingServiceInterface.strReportingServiceURL


            Dim dsdDefinition As DataSourceDefinition = New DataSourceDefinition
            dsdDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store
            dsdDefinition.ConnectString = strConnectionString
            dsdDefinition.Enabled = True
            dsdDefinition.EnabledSpecified = True
            dsdDefinition.Extension = "SQL"
            dsdDefinition.ImpersonateUserSpecified = False
            dsdDefinition.UserName = strUserName ' "UserName"
            dsdDefinition.Password = strPassword ' "Password"
            dsdDefinition.Prompt = Nothing
            dsdDefinition.WindowsCredentials = False


            'Dim PropertyArray As ReportingService2005_WebService.Property() = New ReportingService2005_WebService.Property(0) {}
            'PropertyArray(0) = New ReportingService2005_WebService.Property
            'PropertyArray(0).Name = "Description"
            'PropertyArray(0).Value = "Automatically added DataSource"

            Dim PropertyArray() As ReportingService2005_WebService.Property = { _
                New ReportingService2005_WebService.Property() With {.Name = "Description", .Value = "Automatically added DataSource"} _
            }


            Try
                If String.IsNullOrEmpty(strDescription) Then
                    rs.CreateDataSource(strDataSourceName, strPath, False, dsdDefinition, Nothing)
                Else
                    PropertyArray(0).Value = strDescription
                    rs.CreateDataSource(strDataSourceName, strPath, False, dsdDefinition, PropertyArray)
                End If
            Catch ex As System.Web.Services.Protocols.SoapException
                Console.WriteLine(ex.Detail.InnerXml.ToString())
            End Try
        End Sub ' End Sub CreateDataSource
于 2010-10-14T20:07:36.713 回答
1

长话短说,将客户端应用程序配置文件中的服务地址更改为指向新服务器。

这将是您的部署过程的一部分。

于 2010-10-15T12:10:31.153 回答