Guest User

Untitled

a guest
Aug 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. Server rejects request on self hosted service
  2. Namespace ECDBDatabase.Service
  3. Public Class DatabaseService
  4. <ServiceContract(Name:="DatabaseService", Namespace:="net.tcp://localhost:9010/ECDBDatabase.Service")> _
  5. Public Interface IRPMSDatabaseService
  6. <OperationContract()> _
  7. Function GetHandover(ByVal Username As String, ByVal Password As String) As DataSet
  8. End Interface
  9.  
  10. Public Function GetHandover(ByVal Username As String, ByVal Password As String) As DataSet Implements IRPMSDatabaseService.GetHandover
  11. 'Connection string to Database
  12. Dim ReadConnectionString As String = "data source =localhost;" + "User ID=" & Username + ";Password=" & Password + ";Database=somedatabase"
  13. ReadConnection = New SqlConnection(ReadConnectionString)
  14. 'Fill and return the dataset
  15. Try
  16. dbScriptFile = "some sql file"
  17. objReader = New StreamReader(dbScriptFile)
  18. cmd.CommandText = objReader.ReadToEnd.Replace("Go", ";")
  19. scriptArr = cmd.CommandText.Split(";")
  20. cmd.Connection = ReadConnection
  21. HandoverDataset = New DataSet
  22. HandoverAdapter = _
  23. New SqlDataAdapter(cmd)
  24.  
  25. For i = 0 To scriptArr.Length - 1
  26. cmd.CommandText = scriptArr.GetValue(i)
  27. 'Fill the dataset
  28. HandoverAdapter.Fill(HandoverDataset)
  29. Next
  30. 'Return the dataset.
  31.  
  32. Return HandoverDataset
  33. Catch ex As Exception
  34. Throw ex
  35. End Try
  36. End Function
  37. End Class
  38. End Class
  39. End Namespace
  40.  
  41. Sub Main()
  42. 'Instantiate the service address
  43. Dim baseAddress As Uri = New Uri("net.tcp://localhost:9010/ECDBDatabase.Service")
  44. 'Create the servicehost
  45. Using ECDBHost As New ServiceHost(GetType(ECDBService.ECDBDatabase.Service.DatabaseService.RPMSDatabaseService), baseAddress)
  46.  
  47. Dim smb As New ServiceMetadataBehavior
  48. Dim debug As New ServiceDebugBehavior
  49. smb.HttpGetEnabled = False
  50. smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
  51. debug.IncludeExceptionDetailInFaults = True
  52.  
  53. ECDBHost.Description.Behaviors.Add(smb)
  54.  
  55. ECDBHost.Open()
  56.  
  57. 'Execute commands on console application
  58. Console.WriteLine("Service has started at {0}", baseAddress)
  59. Console.ReadLine()
  60.  
  61. End Using
  62. End Sub
  63.  
  64. Public Function GetHandover(ByVal UserName As String, ByVal Password As String) As DataSet
  65. Try
  66. HandoverDataset = New DataSet
  67.  
  68. tempBinding = New NetTcpBinding()
  69. tempAddress = New EndpointAddress(New Uri("net.tcp://localhost:9010/ECDBDatabase.Service"), New SpnEndpointIdentity(""))
  70. With tempBinding
  71.  
  72. End With
  73. With tempAddress
  74.  
  75. End With
  76. 'Instantiating the channel for the proxy and setting the proxy up to communicate
  77. tempFactory = New ChannelFactory(Of ECDBService.ECDBDatabase.Service.DatabaseService.IRPMSDatabaseService)(tempBinding, tempAddress)
  78. With tempFactory
  79. tempProxy = .CreateChannel()
  80. End With
  81. 'Setting the contracts to the channel
  82. With tempProxy
  83. HandoverDataset = .GetHandover(UserName, Password)
  84.  
  85. End With
  86. Return HandoverDataset
  87. Catch ex As Exception
  88. Throw ex
  89. End Try
  90. End Function
  91.  
  92. Private Sub frmHandover_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  93. 'Load the dataset and bind the controls.
  94. Try
  95. HandoverData = New DatabaseProxyClass.ECDBDatabase.Service.DatabaseProxy
  96.  
  97. User = frmEhawkRPMS.UserN
  98. Pass = frmEhawkRPMS.PassW
  99. HandoverSet = New DataSet
  100. HandoverSet = HandoverData.GetHandover(User, Pass)
  101.  
  102. <?xml version="1.0" encoding="utf-8" ?>
  103. <configuration>
  104. <system.web>
  105. <compilation debug="true" />
  106. </system.web>
  107. <system.serviceModel>
  108. <services>
  109. <service name="ECDBService.ECDBDatabase.Service.RPMSDatabaseService">
  110. <endpoint address="net.tcp://localhost:9010/ECDBDatabase.Service"
  111. binding="netTcpBinding"
  112. contract="ECDBService.ECDBDatabase.Service.IRPMSDatabaseService" />
  113. <endpoint address ="" binding="wsHttpBinding" contract="ECDBService.ECDBDatabase.Service.RPMSDatabaseService">
  114. <!--
  115. Upon deployment, the following identity element should be removed or replaced to reflect the
  116. identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
  117. automatically.
  118. -->
  119. <identity>
  120. <dns value="localhost"/>
  121. </identity>
  122. </endpoint>
  123. <!-- Metadata Endpoints -->
  124. <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
  125. <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
  126. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  127. </service>
  128. </services>
  129. </system.serviceModel>
  130. </configuration>
Add Comment
Please, Sign In to add comment