【问题标题】:MessageSecurityException No signature message parts were specified for messages with the 'http://...' actionMessageSecurityException 没有为带有“http://...”操作的消息指定签名消息部分
【发布时间】:2011-02-17 18:50:29
【问题描述】:

这是客户端和服务器都使用的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IPM_Service" 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="Text" 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="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8080/PM_Service"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPM_Service"
          contract="IPM_Service" name="WSHttpBinding_IPM_Service">
        <identity>

        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

这是我得到错误的代码块。

            ProgrammingMaster_ServiceClient aClient = new ProgrammingMaster_ServiceClient();
            aClient.BeginProgrammingSession(0x01);
            aClient.Close();

第二行是异常发生的地方。 ProgrammingMaster_ServiceClient 是使用 svcutil.exe 工具创建的。

这是我用来启动服务器的代码。

public bool StartService(string aIp)
{
    string lsInstanceId = pFBlock.InstanceId.ToString();
    Uri loBaseAddr = new Uri(string.Format("http://localhost:808{0}/{1}", lsInstanceId, pFBlock.FBlockName));

    pLocalHost = new ServiceHost(typeof(Shadow_ProgrammingMasterService), loBaseAddr);

    Start(aIp);
    return IsHostOpen;
}

private void Start(string aIp)
{
    Shadow_ProgrammingMasterService.SetAPI(this);

    try
    {
        pLocalHost.AddServiceEndpoint(typeof(IProgrammingMaster_Service), new WSHttpBinding(), "PM_Service");

        ServiceMetadataBehavior loSmb = new ServiceMetadataBehavior();
        loSmb.HttpGetEnabled = true;
        pLocalHost.Description.Behaviors.Add(loSmb);
        try
        {
            pLocalHost.Open();
            IsHostOpen = true;
            pPM_Client = new ProgrammingMasterProxyClient(this, pOutput);
            pPM_Client.IpAddress = aIp;
            this.Subscribe(pPM_Client);
            pOutput.setComment("ProgrammingMasterService initialized");
        }
        catch (CommunicationException ce)
        {
            pOutput.setError(ce.Message);
            pLocalHost.Abort();
            IsHostOpen = false;
        }
    }
    catch (CommunicationException ex)
    {
        pOutput.setError(ex.Message);
        pLocalHost.Abort();
        IsHostOpen = false;
        //this.Unsubscribe(pOSTTSClient);
        //pOSTTSClient = null;
    }
}

任何人对可能导致此问题的原因有任何想法吗?

【问题讨论】:

  • 您的服务客户端代理是否完全最新?
  • @Mr.Disapointment - 我是这么认为的,但我想我已经有一段时间没有改变它了。我会检查的。
  • @Mr.Disappointment - 就是这样。谢谢。如果你把它作为一个答案,我会接受它。

标签: c# wcf


【解决方案1】:

在您的情况下发生这种情况的原因很简单,WCF 服务代码本身已被修改、重新编译(并基本上部署在调试器中),而具有现已过时的服务引用的客户端正在期待并取决于某些东西会受到这种变化的影响,因此会发生冲突。

更新客户端的服务参考将纠正此问题。

要继续,上面并不是说一旦服务本身被客户端引用(不破坏客户端),您就不能更改服务本身的任何代码,但是,这样的问题表明对服务的某些部分进行了实质性更改客户端所依赖的服务,例如公开方法的签名、现有DataContract 类型的现有DataMember 属性等。

相比之下,您可以将现有服务调用的方法体更改为您的心脏内容(客户端不关心服务如何工作,只关心如何制作这行得通);您还可以将新成员添加到现有的复合 DataContract 类型,以便新客户端可以轻松使用您的更新,防止出现冗余的 DataType2 类型场景,等等。

【讨论】:

  • 非常感谢!值得注意的是,如果您使用可靠消息传递,则此无用的错误消息可能会被另一条消息掩盖:“在可靠会话完全完成之前,底层安全会话发生故障。可靠会话发生故障。”。此问题的错误仅显示在跟踪日志中。
  • 如果您不使用服务引用怎么办?实际上有什么问题?请注意,此消息与消息安全相关,而不是方法签名。消息中的“签名”是指加密签名。
猜你喜欢
  • 2018-12-02
  • 2014-04-19
  • 1970-01-01
  • 1970-01-01
  • 2013-04-04
  • 1970-01-01
  • 1970-01-01
  • 2012-08-03
  • 2019-01-18
相关资源
最近更新 更多