[英]Not Receiving Messages using netMsmqBinding
可以在以下位置找到文檔示例: http://msdn.microsoft.com/en-us/library/ms789008.aspx和http://msdn.microsoft.com/en-us/library/ms751493.aspx
我知道有關IIS7應用程序池無法啟動的問題(我確實使用預熱技術來嘗試解決此問題),但是即使在Visual Studio中的WebDev下運行,我也無法獲得WCF Web服務來接收來自MSMQ的消息我的本地PC上的Studio 2010。
下面的簡單測試基於上面的文檔,但是即使他們的簡單演示也似乎不起作用,這讓我覺得我已經忽略了一些明顯的東西。
如果您構建以下內容,並使用下面的測試行,則只會寫下第二行。 第一個將進入MSMQ,然后再也不會被目的地接走。
a)“這是一個測試。” b)“!這是一個不同的測試。”
我構建了一個控制台客戶端,該客戶端將一條數據發送到服務端點:
class Program
{
static void Main(string[] args)
{
string input;
while (!string.IsNullOrEmpty(input = Console.ReadLine()))
{
if (input.StartsWith("!") && input.Length > 1)
{
using (var client = new MSMQClient.DirectServiceRef.Service1Client())
{
client.Log(input.Substring(1));
}
}
else
{
using (var client = new MSMQClient.LogServiceRef.Service2Client())
{
client.Log(input);
}
}
}
Console.WriteLine("Done.");
Console.ReadKey();
}
}
App.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService2">
<security mode="None" />
</binding>
<binding name="BasicHttpBinding_IService1">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1910/Service2.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService2" contract="LogServiceRef.IService2"
name="BasicHttpBinding_IService2" />
<endpoint address="http://localhost:1909/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="DirectServiceRef.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Service2是一個簡單的服務,它接收輸入並將其發送到MSMQ。
[ServiceContract]
public interface IService2
{
[OperationContract]
bool Log(string data);
}
public class Service2 : IService2
{
public Service2()
{
var queueName = ConfigurationManager.AppSettings["queueName"];
if (!MessageQueue.Exists(queueName))
{
MessageQueue.Create(queueName, true);
}
}
[OperationBehavior]
public bool Log(string data)
{
using (var client = new MSMQService2.MSMQServiceRef.Service1Client())
{
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
client.Log(data);
scope.Complete();
}
}
return true;
}
}
Web.config文件:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="queueName" value=".\private$\Service1.svc" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netMsmqBinding>
<binding name="msmqBinding">
<security mode="None" />
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="logService">
<endpoint binding="basicHttpBinding"
contract="MSMQService2.IService2" />
</service>
</services>
<client>
<endpoint address="net.msmq://localhost/private/Service1.svc"
binding="netMsmqBinding"
bindingConfiguration="msmqBinding"
contract="MSMQServiceRef.IService1" />
</client>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Service1是一個簡單的服務,它接收輸入並將其記錄到本地文件中。
[ServiceContract]
public interface IService1
{
[OperationContract(IsOneWay=true)]
void Log(string data);
}
public class Service1 : IService1
{
public Service1()
{
var queueName = ConfigurationManager.AppSettings["queueName"];
if (!MessageQueue.Exists(queueName))
{
MessageQueue.Create(queueName, true);
}
}
[OperationBehavior(TransactionAutoComplete=true, TransactionScopeRequired=true)]
public void Log(string data)
{
using (var log = new FileInfo(ConfigurationManager.AppSettings["logFilePath"]).AppendText())
{
log.WriteLine(data);
}
}
}
Web.config文件:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="logFilePath" value="C:\testlog.txt"/>
<add key="queueName" value=".\private$\Service1.svc"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netMsmqBinding>
<binding name="msmqBinding">
<security mode="None" />
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="logService">
<endpoint address="net.msmq://localhost/private/Service1.svc"
binding="netMsmqBinding"
bindingConfiguration="msmqBinding"
contract="MSMQService1.IService1" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
最后一項服務似乎沒有“接收”來自MSMQ的消息。 從桌面運行解決方案時,或者將服務部署到Server 2008 / IIS7部署中,然后在遠程或本地運行客戶端時,都會發生這種情況。
我錯過了什么嗎,還是應該在Windows設置中檢查一些選項?
問候,羅布。
您應該執行以下操作:
1-啟用WCF跟蹤
https://stackoverflow.com/a/4271597/569662
這應該記錄WCF堆棧中的所有失敗,並且應該在服務和客戶端上都啟用它。
2-啟用源日志
將useSourceJournal="true"
添加到客戶端netMsmqBinding配置中。 這將記錄已發送的消息。
3-啟用負面來源日記
將'deadLetterQueue =“ System”添加到服務netMsmqBinding配置中。 這將導致未送達的郵件進入系統死信隊列。
4-啟用MSMQ事件記錄
在服務上,轉到事件查看器->應用程序和服務日志-> Microsoft-> Windows-> MSMQ-> End2End->啟用日志。 這將記錄服務器上msmq中發生的所有事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.