何时添加服务参考?

发布于 2024-09-27 16:08:00 字数 116 浏览 1 评论 0原文

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

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

I'm building a WCF service that will get deployed to a server running IIS. I can add the service reference from the current solution and use it fine.

If I deploy the service to that particular machine, will I need to re-add the service to the application that consumes it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫罗兰の梦幻 2024-10-04 16:08:00

不需要,您只需更改服务 URL 以匹配其他计算机即可。

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

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

No, you just need to change the service URL to match the other machine.

A proxy is generated when you add the service reference and that proxy will work against all servers that host those services - it just needs the right URL.

You only need to update the service refernece when the services exposed changes, e.g. adding a new method or changing a parameter.

花间憩 2024-10-04 16:08:00

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

这就是一个 .NET 类。

如果您向服务添加了其他方法,则只需删除并重新添加引用。

例如,报告服务 2005 Web 服务:

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

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

No. The way it works is, when you add the reference to your project, it queries the service URL given and creates, over XML via SOAP, a list of all classes and methods of your particular service.

This is then a .NET class.

You only need to remove and readd the reference if you added additional methods to your service.

E.g. the reporting service 2005 web service:

You add the reference to your project, then import the namespace.

Imports ReportingServiceInterface.ReportingService2005_WebService

You instanciate an object of this class, and pass it the URL.
Then you call the WebService method via the instance of this class.

See below:

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
对风讲故事 2024-10-04 16:08:00

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

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

Long story short, change the service address in the configuration file of the client application to point to the new server.

This will be part of your deployment procedure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文