【问题标题】:When to add a service reference?何时添加服务参考?
【发布时间】:2010-10-14 19:58:28
【问题描述】:

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

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

【问题讨论】:

    标签: wcf iis service-reference


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      没有。它的工作方式是,当您将引用添加到您的项目时,它会查询给定的服务 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
      

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-05-04
          • 1970-01-01
          • 1970-01-01
          • 2015-04-09
          • 2015-11-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多