Windows 2008下在IIS中寄宿WCF MSMQ的方法
由于工作需要,最近几天在研究Windows 2008下如何在IIS中寄宿WCF MSMQ,中间遇到不少问题,现将操作方法整理一下,方便其他朋友参考。
一、编写服务端代码在本例中,添加WCF服务MyGreeting.svc,服务端代码如下:
1、服务契约
1 using System.ServiceModel; 2 3 namespace IisMsmqServer 4 { 5 [ServiceContract] 6 public interface IMyGreeting 7 { 8 [OperationContract(IsOneWay = true)] 9 void Hello(string name); 10 } 11 }
View Code 2、服务实现
1 using System; 2 using System.IO; 3 using System.Web.Hosting; 4 5 namespace IisMsmqServer 6 { 7 public class MyGreeting : IMyGreeting 8 { 9 public void Hello(string name) 10 { 11 string msg = string.Format("{0}[Info]...你好,{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name); 12 string fileName = Path.Combine(HostingEnvironment.MapPath("~"), "Log", "我的日志.txt"); 13 TextHelper.WriteLineAppend(fileName, msg); 14 } 15 } 16 }
View Code 二、配置服务使用Edit Wcf Configuration工具或手工编辑WCF配置文件,其中绑定为netMsmqBinding:
<?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> </appSettings> <system.web> <compilation targetFramework="4.5" debug="true"/> <httpRuntime targetFramework="4.5"/> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="msmqBehav"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <netMsmqBinding> <binding name="msmq" durable="false" useActiveDirectory="false" deadLetterQueue="Custom" exactlyOnce="false"> <security mode="None"> <transport msmqAuthenticationMode="None" msmqProtectionLevel="None"/> <message clientCredentialType="None"/> </security> </binding> </netMsmqBinding> </bindings> <services> <service behaviorConfiguration="msmqBehav" name="IisMsmqServer.MyGreeting"> <endpoint address="net.msmq://localhost/private/huatao" binding="netMsmqBinding" bindingConfiguration="msmq" contract="IisMsmqServer.IMyGreeting"/> </service> </services> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --> <directoryBrowse enabled="false"/> </system.webServer> </configuration>
View Code 三、创建消息队列 1、创建队列温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69934.html