2011-02-17 16 views
4

這裏是由客戶端和服務器都使用該配置文件MessageSecurityException的消息被指定用的「http:// ...」無簽名的消息部分行動

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

任何人有任何想法可能會導致這種情況?

+0

您的服務客戶端代理是完全最新的嗎? – 2011-02-17 19:00:40

+0

@ Mr.Disapointment - 我這麼認爲,但我想我暫時還沒有改變它。我會檢查的。 – scott 2011-02-17 19:11:32

回答

11

您的情況發生這種情況很簡單,WCF服務代碼本身已被修改,重新編譯(並且本質上部署在調試器中),而具有現在過時的服務引用的客戶端期望並取決於受到這種變化的影響,從而產生衝突。

更新客戶端的服務參考將更正此問題。

要繼續,上面並不是說,一旦服務本身被客戶端引用(不會破壞客戶端),就不能更改服務本身內的任何代碼,但是,這樣的問題表明對部分客戶端所依賴的服務,如已公開方法的簽名,現有的DataContract類型的屬性等。

相反,你可以改變調用你的心臟的內容(客戶不關心如何服務工作,只是如何讓工作)的現有服務的方法體;您還可以將新成員添加到現有的複合DataContract類型中,以便新客戶端可以隨時使用更新,防止DataType2類型方案具有冗餘,等等。