2012-02-22 16 views
3

我試圖創建一個MSMQ WCF服務,但我在運行代碼的麻煩。嘗試創建服務的實例時失敗。我已經安裝了MSMQ,並且可以確認有一個私人創建一個名爲「servicemodelsamples未能得到MSMQ WCF窗口服務的功能

當運行的服務,我收到以下錯誤;

服務無法啓動。 System.InvalidOperationException:有是 錯誤打開隊列。確保已安裝MSMQ和運行, 隊列存在,並且必須從讀適當授權。內部異常可能包含其他信息。 ---> System.ServiceModel.MsmqException:無法識別錯誤-1072824283(0xc00e0025):同時打開 隊列時發生錯誤。不能從隊列發送或接收消息 。確保已安裝MSMQ並運行 。還要確保隊列可用 必需的訪問模式和授權打開。

控制服務接口和實現。

[ServiceContract()] 
public interface IControlService 
{ 
    [OperationContract(IsOneWay = true)] 
    void PricingAlert(int eventid, int marketid); 
} 

public class ControlService : IControlService 
{ 
    public ControlService() 
    { } 

    public void PricingAlert(int eventid, int marketid) 
    { 
     Console.WriteLine("Acknowledged"); 
    } 
} 

Service1.cs服務啓動代碼。

protected override void OnStart(string[] args) 
{ 
    Thread.Sleep(10000); 
    string queueName = Settings.Default["queueName"].ToString(); 

    if (!MessageQueue.Exists(queueName)) 
     MessageQueue.Create(queueName, true); 

    if (myServiceHost != null) 
    { 
     myServiceHost.Close(); 
    } 
    myServiceHost = new ServiceHost(typeof(ControlService)); 
    myServiceHost.Open(); // *** Code Fails Here 
} 

應用程序配置;

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="ControlService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <netMsmqBinding> 
     <binding name="netMsmqBindingConfig"> 
      <security mode="None"> 
      </security> 
     </binding> 
     </netMsmqBinding> 
    </bindings> 
    <services> 
     <service name="TheControlService.ControlService" behaviorConfiguration="MSMQBindingBehaviour"> 
     <endpoint address="net.msmq://172.26.2.11/private/ServiceModelSamples" 
        binding="netMsmqBinding" bindingConfiguration="netMsmqBindingConfig" 
        contract="TheControlService.IControlService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MSMQBindingBehaviour"> 
      <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/Hello/" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <system.diagnostics> 
    <trace autoflush="true" /> 
    <sources> 
     <source name="System.ServiceModel" 
       switchValue="Information, ActivityTracing" 
       propagateActivity="true"> 
     <listeners> 
      <add name="sdt" 
       type="System.Diagnostics.XmlWriterTraceListener" 
       initializeData="controlserviceerrors.svclog" /> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> 
    <applicationSettings> 
    <ControlService.Properties.Settings> 
     <setting name="queueName" serializeAs="String"> 
     <value>.\private$\ServiceModelSamples</value> 
     </setting> 
    </ControlService.Properties.Settings> 
    </applicationSettings> 
</configuration> 

任何想法?我懷疑這可能是因爲我已經將代碼基於一個Winforms應用程序的例子。

+0

上次發生這種事對我來說這實際上是* *安全問題。在某些操作系統中,默認權限不允許您從隊列中讀取。 – JohnC 2012-02-22 19:28:44

+0

你找到了這個解決方案嗎?我有一個類似的問題;從Visual Studio運行集成測試工作,但在構建服務器上運行它們(代理位於我的計算機上),我會得到相同的異常消息。 – bigfoot 2012-05-02 13:28:05

+0

我們遇到了這個問題,並通過刪除和重新添加隊列來找到解決方法。我懷疑這可能是一條紅鯡魚,但你可以嘗試。此外,[此MSMQ常見問題](http://www.docstoc.com/docs/68300738/MSMQ-faq)提到它可能是一個Active Directory問題。 – Richard 2012-06-21 13:15:30

回答

1

檢查在其下運行服務的用戶。添加許可手動的隊列。 如果隊列已經打破權限,您應該手動C:\Windows\System32\msmq\storage\lqs使用記事本重置權限。