服务器拒绝自托管服务的请求

时间:2011-10-14 03:23:27

标签: vb.net wcf hosting self

我使用代理创建了自托管服务 服务和合同

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)

当我尝试从代理访问服务时,我的问题开始出现以下错误:“数据错误:由于内部错误,服务器无法处理请求。 有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自servicebahviorattribute或配置行为)以将异常信息发送回客户端,或根据Microsoft.net Framework 3.0 SDk文档启用跟踪并检查服务器跟踪日志。“ 我已经尝试启用异常,但得到的错误表明已经存在服务行为,并且它不允许我将exceptiondetailfaults添加到服务行为中,并且没有太多的例子可以在自我中添加使用VB托管WCF。 我正在寻找一些关于在VB中添加异常的建议,或者如果有人注意到我的问题是什么开始并且可以指出它也会非常感激。 此处还有我的应用程序配置,它位于启动服务的控制台应用程序中。

<?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>

0 个答案:

没有答案