开发者

When to add a service reference?

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 dep开发者_StackOverflow社区loy the service to that particular machine, will I need to re-add the service to the application that consumes it?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜