WCF相关 - System.ServiceModel.ProtocolException:

时间:2014-08-01 15:44:07

标签: wcf

我尝试了不同的配置但没有成功......这个错误是这些配置的最新错误.....任何想法?

注意:我从服务器上的控制台应用程序托管服务,然后从位于另一台服务器上的Web应用程序(客户端)调用该服务。

我不关心安全问题所以我设置安全模式="无"。

我得到的错误:

System.ServiceModel.ProtocolException: The remote endpoint has sent an unrecognized fault with namespace, http://www.w3.org/2003/05/soap-envelope, name Sender, and reason The message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.. The channel could not be opened.

另外,我确实注意到在添加服务引用时放在Web应用客户端应用上的BackupServerService.wdl文件中出现此错误。

这些节点带有下划线,并声明:the schema referenced from this location in your document contains errors。     "无法解析架构位置属性"

<wsdl:types>
  <xsd:schema targetNamespace="http://tempuri.org/Imports">
    <xsd:import schemaLocation="http://"I removed the IP"/Application/BackupServerServiceLibrary/BackupServerService?xsd=xsd0" 
                namespace="http://tempuri.org/" />
    <xsd:import schemaLocation="http://"I removed the IP:8000"/Application/BackupServerServiceLibrary/BackupServerService?xsd=xsd1"
                namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
  </xsd:schema>
</wsdl:types>

我的客户端web.config文件如下所示:(注意:&#34; IP地址&#34;&#34; userPrincipalName&#34;这些都是虚构的。)

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="WSHttpBinding_IBackupServerService" 
               closeTimeout="00:01:00" openTimeout="00:10:00"
               receiveTimeout="01:10:00" sendTimeout="00:10:00">
        <security mode="None">
          <transport clientCredentialType="None" />
          <message establishSecurityContext="false" />
        </security>
        <reliableSession enabled="true" />
      </binding>
    </wsHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://"I removed the IP:8000"/Application/BackupServerServiceLibrary/BackupServerService/BackupServerService"
              binding="wsHttpBinding" 
              bindingConfiguration="WSHttpBinding_IBackupServerService"
              contract="ServiceReference1.IBackupServerService" 
              name="WSHttpBinding_IBackupServerService">
      <identity>
        <userPrincipalName value="xxxxx-415-B\djbrown" />
      </identity>
    </endpoint>
  </client>
</system.serviceModel>  

我的服务app.config如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="BackupServerPassword" value="Danspassword" />
    <add key="StorageFolderName" value="C:\Backupstorage-backups" />
    <add key="FileZilla" value="C:\Program Files (x86)\FileZilla Server" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
     app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="BackupServerServiceLibrary.BackupServerService">
        <host>
          <baseAddresses>
            <add baseAddress="/BackupServerServiceLibrary/BackupServerService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding"
                  contract="BackupServerServiceLibrary.IBackupServerService"
                  bindingConfiguration="NoSecurityConfig">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" 
                  contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="NoSecurityConfig">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
          <reliableSession enabled="true" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

我的服务界面:

Namespace BackupServerServiceLibrary

  <ServiceContract()>
  Public Interface IBackupServerService

      <OperationContract()> 
      <WebInvoke(Method:="GET")>
      Function DeleteBySpaceIdProcess(ByVal strIpAddress As String, ByVal strPassword As String, ByVal iBackupSpaceId As Integer) As Boolean

      <OperationContract()> 
      <WebInvoke(Method:="GET")>
      Function AddBackupSpaceProcess(ByVal strIpAddress As String, ByVal strPassword As String, ByVal iBackupSpaceId As Integer, ByVal iPublicFtpAccountId As
        Integer, ByVal strPublicFtpAccountPassword As String, ByVal iPrivateFtpAccountId As Integer, ByVal strPrivateFtpAccountPassword As String) As Boolean

      <OperationContract()> 
      <WebInvoke(Method:="GET")>
      Function UpdateFtpAccountsProcess(ByVal strIpAddress As String, ByVal strPassword As String, ByVal iBackupSpaceId As Integer, ByVal iFtpAccountId As Integer,
        ByVal strFtpAccountPassword As String, ByVal strAccountType As String) As Boolean

    End Interface
End Namespace

我从网络应用程序(客户端)调用的服务方法之一:(代码减少只显示相关部分)

Namespace BackupServerServiceLibrary

    <ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)>
    Public Class BackupServerService
        Implements IBackupServerService

        Public Function DeleteBySpaceIdProcess(ByVal strIpAddress As String, ByVal strPassword As String, ByVal iBackupSpaceId As Integer) As Boolean Implements IBackupServerService.DeleteBySpaceIdProcess

            strEncryptedBackupServerPassword = GetAppSetting(strKeyPassword)

            If strEncryptedBackupServerPassword = strPassword Then
                strStorageFolderName = GetAppSetting(strkeyStorageFolderName)
                strFileZillaFilepathAndName = GetAppSetting(strKeyFileZilla)

                If ((strStorageFolderName = "Not Found" Or strStorageFolderName = "Error") Or (strFileZillaFilepathAndName = "Not Found" Or strFileZillaFilepathAndName = "Error")) Then
                    Throw New System.Exception("Critical Error: during delete of space - cannot find the storage folder name or FileZilla entry in the app config. Space Id: " & iBackupSpaceId.ToString())
                Else
                    strVhdFilepathAndName = "strStorageFolderName" & "\" & iBackupSpaceId.ToString() & "\" & iBackupSpaceId.ToString() & ".vhd"
                    If File.Exists(strVhdFilepathAndName) Then
                        Try
                            UnmountVHDFile(strStorageFolderName & "\" & iBackupSpaceId.ToString() & "\DiskpartUnmountVHDScript.txt", strVhdFilepathAndName)
                            Try
                                DeleteSpacesFolderAndFiles(strStorageFolderName & "\" & iBackupSpaceId.ToString(), strStorageFolderName & "\Boot-Scripts\" & iBackupSpaceId.ToString() & "-boot.txt")
                                Try
                                    DeleteXMLEntries(strFileZillaFilepathAndName, iBackupSpaceId)
                                    Try
                                        ReloadFileZillaConfig()
                                    Catch ex As Exception
                                        Throw New System.Exception("Critical Error: during delete of space - reload of FileZilla failed. Space Id: " & iBackupSpaceId.ToString() & " from: ReloadFileZillaConfig() ---> " & ex.Message)
                                    End Try
                                Catch ex As Exception
                                    Throw New System.Exception("Critical Error: during delete of space - Space Id: " & iBackupSpaceId.ToString() & " from: DeleteXMLEntries() ---> " & ex.Message)
                                End Try
                            Catch ex As Exception
                                Throw New System.Exception("Critical Error during deletes:  Space Id: " & iBackupSpaceId.ToString() & " from: DeleteSpacesFolderAndFiles() ---> " & ex.Message)
                            End Try
                        Catch ex As Exception
                            Throw New System.Exception("Critical Error: during delete of space - Space Id: " & iBackupSpaceId.ToString() & " from: UnmountVHDFile() ---> " & ex.Message)
                        End Try
                    Else
                        Throw New System.Exception("Critical Error: VHD file does exist. Space Id: " & iBackupSpaceId.ToString())
                    End If
                End If
            Else
                Throw New System.Exception("Critical Error: during delete of space - password not found. It's invalid. Space Id: " & iBackupSpaceId.ToString())
            End If

            Return bSuccess = True
        End Function
    End Class
End Namespace

网络应用(客户端)服务电话:

Dim proxyClient As New BackupServerServiceClient()

Try
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Step 2: Call the service operations.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Call the service operation.
    proxyClient.DeleteBySpaceIdProcess(strBackupServerIpAddress, 
    strBackupServerPassword, Request("backupspaceid"))

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Step 3: Closing the client gracefully closes the connection and cleans up resources.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    proxyClient.Close()                        '
    Catch timeout As TimeoutException
        ' Handle the timeout exception.
        bSuccess = False
        lblMessage.Text = "Critical Error - from web service - at timeout. " & 
        timeout.ToString()
        proxyClient.Abort()
    Catch commException As CommunicationException
        ' Handle the communication exception.
        bSuccess = False
        lblMessage.Text = "Critical Error - from web service - at commException. " 
        & commException.ToString()
        proxyClient.Abort()
    Catch ex As Exception
        ' Handle the exceptions from the web service call.
        bSuccess = False
        lblMessage.Text = "Critical Error - from web service. " & ex.Message
    Finally
        If proxyClient.State = CommunicationState.Faulted Then
            bSuccess = False
            If lblMessage.Text = "" Then
                lblMessage.Text = "Critical Error - network issue on call to the 
                web service. Contact IT, do not continue."
            Else
                lblMessage.Text = lblMessage.Text & " ---> Additional error - 
                 network issue on call to the web service."
            End If
            proxyClient.Abort()
        End If
    End Try

最后,当我在Chrome浏览器中输入网址时。页面看起来都很好。

0 个答案:

没有答案