Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Server rejects request on self hosted service
- Namespace ECDBDatabase.Service
- Public Class DatabaseService
- <ServiceContract(Name:="DatabaseService", Namespace:="net.tcp://localhost:9010/ECDBDatabase.Service")> _
- Public Interface IRPMSDatabaseService
- <OperationContract()> _
- Function GetHandover(ByVal Username As String, ByVal Password As String) As DataSet
- End Interface
- Public Function GetHandover(ByVal Username As String, ByVal Password As String) As DataSet Implements IRPMSDatabaseService.GetHandover
- 'Connection string to Database
- Dim ReadConnectionString As String = "data source =localhost;" + "User ID=" & Username + ";Password=" & Password + ";Database=somedatabase"
- ReadConnection = New SqlConnection(ReadConnectionString)
- 'Fill and return the dataset
- Try
- dbScriptFile = "some sql file"
- objReader = New StreamReader(dbScriptFile)
- cmd.CommandText = objReader.ReadToEnd.Replace("Go", ";")
- scriptArr = cmd.CommandText.Split(";")
- cmd.Connection = ReadConnection
- HandoverDataset = New DataSet
- HandoverAdapter = _
- New SqlDataAdapter(cmd)
- For i = 0 To scriptArr.Length - 1
- cmd.CommandText = scriptArr.GetValue(i)
- 'Fill the dataset
- HandoverAdapter.Fill(HandoverDataset)
- Next
- 'Return the dataset.
- Return HandoverDataset
- Catch ex As Exception
- Throw ex
- End Try
- End Function
- End Class
- End Class
- End Namespace
- Sub Main()
- 'Instantiate the service address
- Dim baseAddress As Uri = New Uri("net.tcp://localhost:9010/ECDBDatabase.Service")
- 'Create the servicehost
- Using ECDBHost As New ServiceHost(GetType(ECDBService.ECDBDatabase.Service.DatabaseService.RPMSDatabaseService), baseAddress)
- Dim smb As New ServiceMetadataBehavior
- Dim debug As New ServiceDebugBehavior
- smb.HttpGetEnabled = False
- smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
- debug.IncludeExceptionDetailInFaults = True
- ECDBHost.Description.Behaviors.Add(smb)
- ECDBHost.Open()
- 'Execute commands on console application
- Console.WriteLine("Service has started at {0}", baseAddress)
- Console.ReadLine()
- End Using
- End Sub
- Public Function GetHandover(ByVal UserName As String, ByVal Password As String) As DataSet
- Try
- HandoverDataset = New DataSet
- tempBinding = New NetTcpBinding()
- tempAddress = New EndpointAddress(New Uri("net.tcp://localhost:9010/ECDBDatabase.Service"), New SpnEndpointIdentity(""))
- With tempBinding
- End With
- With tempAddress
- End With
- 'Instantiating the channel for the proxy and setting the proxy up to communicate
- tempFactory = New ChannelFactory(Of ECDBService.ECDBDatabase.Service.DatabaseService.IRPMSDatabaseService)(tempBinding, tempAddress)
- With tempFactory
- tempProxy = .CreateChannel()
- End With
- 'Setting the contracts to the channel
- With tempProxy
- HandoverDataset = .GetHandover(UserName, Password)
- End With
- Return HandoverDataset
- Catch ex As Exception
- Throw ex
- End Try
- End Function
- Private Sub frmHandover_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- 'Load the dataset and bind the controls.
- Try
- HandoverData = New DatabaseProxyClass.ECDBDatabase.Service.DatabaseProxy
- User = frmEhawkRPMS.UserN
- Pass = frmEhawkRPMS.PassW
- HandoverSet = New DataSet
- HandoverSet = HandoverData.GetHandover(User, Pass)
- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <system.web>
- <compilation debug="true" />
- </system.web>
- <system.serviceModel>
- <services>
- <service name="ECDBService.ECDBDatabase.Service.RPMSDatabaseService">
- <endpoint address="net.tcp://localhost:9010/ECDBDatabase.Service"
- binding="netTcpBinding"
- contract="ECDBService.ECDBDatabase.Service.IRPMSDatabaseService" />
- <endpoint address ="" binding="wsHttpBinding" contract="ECDBService.ECDBDatabase.Service.RPMSDatabaseService">
- <!--
- Upon deployment, the following identity element should be removed or replaced to reflect the
- identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
- automatically.
- -->
- <identity>
- <dns value="localhost"/>
- </identity>
- </endpoint>
- <!-- Metadata Endpoints -->
- <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
- <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
- <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
- </service>
- </services>
- </system.serviceModel>
- </configuration>
Add Comment
Please, Sign In to add comment