某些远程站点通过WCF发送二进制数据的问题

时间:2011-10-19 17:42:17

标签: c# wcf

我遇到的这个问题不会一直发生,但对于特定的WCF客户端,我记录了以下异常:

  

System.ServiceModel.Security.MessageSecurityException

     

从另一方收到了不安全或不正确安全的故障   派对。请参阅内部FaultException以获取故障代码和详细信息。

     

System.ServiceModel.Security.MessageSecurityException:不安全或   从另一方收到了错误的安全故障。见   内部FaultException为故障代码和细节。 --->   System.ServiceModel.FaultException:验证时发生错误   消息的安全性。 ---内部异常堆栈跟踪结束   ---服务器堆栈跟踪:在System.ServiceModel.Security.SecuritySessionClientSettings 1.SecurityRequestSessionChannel.ProcessReply(Message reply, TimeSpan timeout, SecurityProtocolCorrelationState correlationState) at System.ServiceModel.Security.SecuritySessionClientSettings 1.SecurityRequestSessionChannel.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannel.Call(String action,   Boolean oneway,ProxyOperationRuntime操作,Object [] ins,   对象[]出局,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannel.Call(String action,   Boolean oneway,ProxyOperationRuntime操作,Object [] ins,   对象[]出局)   System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage   methodCall,ProxyOperationRuntime operation)at   System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天   消息)在[0]处重新抛出异常:at   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天   reqMsg,IMessage retMsg)at   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培;   msgData,Int32类型)at   Proxy.ExecutionResultsUpdateService.IExecutionResultsUpdateService.SaveBinaryResults(SaveBinaryResultsRequest   请求)   Proxy.ExecutionResultsUpdateService.ExecutionResultsUpdateServiceClient。   的> Proxy.ExecutionResultsUpdateService.IExecutionResultsUpdateService.SaveBinaryResults(SaveBinaryResultsRequest   请求)在   LoggingExecutionResultsUpdateServiceClient.SaveBinaryResults(SaveBinaryResultsRequest   请求)在ClientServices.ResultsController.Send(IEnumerable`1   resultsList)在NMA.StartAutomaticAgent()at   MainApplication.Start()

客户抛出了这个异常。

SaveBinaryResults的服务代码是:

[ServiceContract(Name="IExecutionResultsUpdateService")]
public interface IExecutionResultsUpdateService_v1_0_1 : IExecutionResultsUpdateService
{
    [OperationContract(Name="SaveBinaryResults")]
    void SaveSQLResults(byte[] data, string serverXml, Guid clientInstanceId, int moduleId, Guid batchIdentifier);
}

   public void SaveSQLResults(byte[] data, string serverXml, Guid clientInstanceId, int moduleId, Guid batchIdentifier)
    {
        DataSet dataSet = (DataSet)new BinaryFormatter().Deserialize(new MemoryStream(data));

        try
        {
            XmlDocument serverDocument = new XmlDocument();
            serverDocument.LoadXml(serverXml);

            executionResultsRepository.Save(dataSet, serverDocument);
            executionHistoryRepository.SaveModuleExecution(clientInstanceId, moduleId, true, null, batchIdentifier);
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            executionHistoryRepository.SaveModuleExecution(clientInstanceId, moduleId, false, ex.ToString(), batchIdentifier);
            throw new FaultException<System.Data.SqlClient.SqlException>(ex, new FaultReason(ex.Message));
        }
    }

IExecutionResultsUpdateService的客户端代理配置为:

<binding name="WSHttpBinding_IExecutionResultsUpdateService"
  closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
  sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false"
  hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
  maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8"
  useDefaultWebProxy="true" allowCookies="false">
  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
  <reliableSession ordered="true" inactivityTimeout="00:10:00"
    enabled="false" />
  <security mode="Message">
    <transport clientCredentialType="Windows" proxyCredentialType="None"
      realm="" />
    <message clientCredentialType="UserName" negotiateServiceCredential="true"
      algorithmSuite="Default" establishSecurityContext="true" />
  </security>
</binding>

服务配置

<service behaviorConfiguration="ServiceBehavior" 
    name="Services.ExecutionResultsUpdateService">
    <endpoint binding="wsHttpBinding" 
      bindingConfiguration="MtomWsHttpBindingForBigArrays" 
      contract="Services.IExecutionResultsUpdateService_v1_0_1" 
      address="/ExecutionResults"/>
    <endpoint binding="wsHttpBinding" 
      bindingConfiguration="wsHttpBinding" 
      contract="Services.IExecutionResultsUpdateService_v1_0_1"/>
    <host>
      <baseAddresses>
      <add baseAddress="http://[ipaddress]/ExecutionResultsUpdateService.svc"/>
      </baseAddresses>
    </host>
</service>

   <binding name="MtomWsHttpBindingForBigArrays" 
         maxReceivedMessageSize="2147483647" 
         messageEncoding="Mtom" 
         receiveTimeout="5"              
         useDefaultWebProxy="false">
          <readerQuotas maxDepth="2147483647" 
             maxStringContentLength="2147483647" 
             maxArrayLength="2147483647" 
             maxBytesPerRead="2147483647" 
             maxNameTableCharCount="2147483647" />
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
    </binding>

客户端代理的一部分如下所示:

public interface IExecutionResultsUpdateService
{
    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IExecutionResultsUpdateService/ReportPackageCompletion", ReplyAction="http://tempuri.org/IExecutionResultsUpdateService/ReportPackageCompletionResponse" +
        "")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    void ReportPackageCompletion(string clientInstanceId, int packageId);

    // CODEGEN: Parameter 'data' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IExecutionResultsUpdateService/SaveBinaryResults", ReplyAction="http://tempuri.org/IExecutionResultsUpdateService/SaveBinaryResultsResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    Proxy.ExecutionResultsUpdateService.SaveBinaryResultsResponse SaveBinaryResults(Proxy.ExecutionResultsUpdateService.SaveBinaryResultsRequest request);
}

注意:两个终点是因为我必须支持这个服务的两个版本。具有绑定“MtomWsHttpBindingForBigArrays”的服务是导致我的问题的服务。 (另一个做同样的事情,但接受了一个DataSet作为参数,除了一个byte [],我很快发现这是一个低效和不好的做法。)

有没有人知道如果摆脱这个异常是我的控制?我可以在客户端或服务配置文件上进行任何配置更改吗?

如果您需要我的任何信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

每次客户拨打电话时都会抛出错误吗?如果是,请检查客户端上的时钟/时区/日期。