文档示例可在此处找到http://msdn.microsoft.com/en-us/library/ms789008.aspx和http://msdn.microsoft.com/en-us/library/ms751493.aspx
我知道围绕IIS7应用程序池不启动的问题(我确实使用预热技术来尝试和解决这个问题),但是我无法让我的web服务从MSMQ服务接收消息,即使在本地PC上运行在Visual Studio2010的WebDev下。
下面的简单测试基于上面的文档,但即使是他们的简单演示似乎也不起作用,这让我觉得我忽略了一些非常明显的东西。
如果您构建以下代码,并使用下面的测试行,则只会写出第二行代码。第一个将进入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的消息。无论是在我的桌面上运行解决方案时,还是在我将服务部署到Server2008/ IIS7部署并远程或本地运行客户端时,都会发生这种情况。
我是否遗漏了什么,或者是否有一些选项我应该在我的Windows设置中检查?
问候你,罗伯。
发布于 2013-10-09 16:48:44
您应该执行以下操作:
1-启用WCF跟踪
https://stackoverflow.com/a/4271597/569662
这应该记录WCF堆栈中的任何故障,并且应该在服务和客户端上都启用。
2-启用源日志记录
在客户端netMsmqBinding配置中添加useSourceJournal="true"。这将记录已发送的消息。
3-启用负源日志记录
在您的服务netMsmqBinding配置中添加‘deadLetterQueue=’system。这将导致未送达的消息进入系统死信队列。
4-启用MSMQ事件日志记录
在服务上,转到事件查看器->应用程序和服务日志-> Microsoft -> Windows -> MSMQ -> End2End ->启用日志。这将记录服务器上msmq中发生的所有事情。
https://stackoverflow.com/questions/19251066
复制相似问题