【发布时间】:2015-08-20 15:54:09
【问题描述】:
我已经研究这个问题一个多星期了。
我已经取得了很大的进步,但是我遇到了一个我无法跟踪或调试的问题。
我正在 Windows 8.1 机器上使用 VS 2015 .NET Framework 4 进行开发。
Web 服务托管在与我的开发环境相同域的 Windows Server 2012 机器上的 IIS 8 中。
我能够使用 net.tcp 端点调用另一个 Web 服务并成功获得返回。
我相信 IIS 已正确设置为使用 msmq 端点托管 Web 服务,但是该 Web 服务在我的开发机器上运行时不会创建消息队列,也不会创建消息队列。
我不知道如何确定原因。
当我运行客户端应用程序时,它会动态创建一个消息队列以供 Web 服务与之对话,它确实会创建消息队列,但客户端是作为控制台应用程序运行的。
网络服务
[AuthenticationBehavior]
public class LeaseService : ILeasesService
{
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void SaveLease(ILease lease)
{
}
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void InsertLeaseEntries(ILeaseEntry[] entries)
{
}
}
}
网络服务主机
class Program
{
private static WebServiceHost _host;
static void Main(string[] args)
{
var queue = @".\private$\ServerLeasesQueue";
if (!MessageQueue.Exists(queue)) MessageQueue.Create(queue, true);
_host = new WebServiceHost(typeof (LeaseService),
new Uri(@"http://localhost:8080/LeaseService"));
_host.Description.Name = "Culbreath.Leases.LeaseService";
_host.Description.Behaviors.Add(new ServiceMetadataBehavior
{
HttpGetEnabled = true,
HttpGetUrl = new Uri(@"http://localhost:8080/LeaseService")
});
var netMsmqBinding = new NetMsmqBinding(NetMsmqSecurityMode.Transport);
netMsmqBinding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;
netMsmqBinding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
_host.AddServiceEndpoint(
typeof(ILeasesService),
netMsmqBinding,
new Uri(@"net.msmq://localhost/private/ServerLeasesQueue"));
_host.Open();
}
}
【问题讨论】:
-
您能否澄清一下:您是否试图通过托管在 IIS 中的 netMsmqBinding 公开服务?为什么您的“Web 服务主机”是控制台应用程序?这是什么意思:当我运行客户端时,它会动态地为 Web 服务创建一个消息队列以与之对话?服务操作暴露所有return void;没有返回类型,因此不会有“顶嘴”。
-
另外你的代码示例太长了。请删除与问题无关的所有内容
-
@TomRedfern Web 服务托管在 Windows 2012 服务器机器上的 IIS 中。客户端是一个控制台应用程序。客户端向 Web 服务发送消息,但由于 Web 服务尚未创建消息队列,因此未收到该消息。
标签: c# web-services wcf message-queue msmq