MessageSecurityException No signature message parts were specified for messages with the 'http://…' action

为君一笑 提交于 2020-01-30 05:26:48

问题


here is the config file used by both the client and the server

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

this is the block of code where I get the error.

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

The second line is where the exception happens at. ProgrammingMaster_ServiceClient is created using the svcutil.exe tool.

this is the code i'm using to start the server.

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;
    }
}

anyone have any ideas of what could be causing this?


回答1:


The reason this occurs in your case is simply that the WCF service code itself has been modified, recompiled (and essentially deployed in the debugger) while the client, which has a now outdated service reference, is expecting and depending on something subject to that change and hence conflicts ensue.

Updating the service reference for the client will correct this problem.

To continue, the above is not to say you can't change any code within the service itself once it is referenced by a client (without breaking the client), however, so such a problem suggests substantial changes to parts of the service that the client is depending on, such as the signatures of exposed methods, existing DataMember properties of existing DataContract types and the like.

In contrast you can alter the method body of the existing service calls to your heart's content (the client doesn't care how the service works, just how to make it work); you can also add new members to existing composite DataContract types so that new clients may consume your updates readily, preventing DataType2 type scenarios with redundancy, and so on.



来源:https://stackoverflow.com/questions/5033217/messagesecurityexception-no-signature-message-parts-were-specified-for-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!