我正在构建一个带有 2 个 WCF 服务的系统。两者都是 IIS 托管的。目前,它们都驻留在一个 VS2010 网站应用程序中,使用 Derfault 网站在我的本地 IIS7(Windows 7)上运行。我在两者上都启用了 net.tcp。
服务1
- 使用 webHttpBinding 接受 HTTP 帖子
- 将数据包装在可序列化的复合对象中
- 使用 netMsmqBinding 将复合对象发送到 Service2(我们希望)
服务2
- 收到所述消息并对其进行处理
服务 1 按预期工作,但是我们的代码不是将消息放在配置的私有队列上,而是在“传出队列”下创建一个新队列,并带有句柄
DIRECT=TCP:127.0.0.1\private$\Service2/Service2.svc
note the forward slash
当然,Service2 永远不会看到该消息——这是我第一次尝试这种结构,所以我不确定 Service2 是否因为它的位置而错过了该消息,但根据我所读到的内容,它似乎是这样的——我没有遇到任何提及此队列创建行为的内容。
问题:
我这样做是否正确(结构、web.config 或代码有问题)?
在 VS Debug 中正确完成后,Service1 的
proxy.ProcessForm(formMessage);
在我的 Service2 代码中打断点,还是有另一种方法来处理 Service2 调试(例如,ala windows 服务)?
服务 1 Web.Config
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpFormBinding" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
<netMsmqBinding>
<binding name="MsmqFormMessageBindingClient" exactlyOnce="false" useActiveDirectory="false" >
<security mode="None">
<message clientCredentialType="None"/>
<transport msmqAuthenticationMode="None" msmqProtectionLevel="None" />
</security>
</binding>
</netMsmqBinding>
</bindings>
<client>
<endpoint
name="HttpServiceWebEndpoint"
address=""
binding="webHttpBinding"
bindingConfiguration="webHttpFormBinding"
contract="Service1.HttpService.IHttpServiceWeb" />
<endpoint name="MsmqFormMessageBindingClient"
address="net.msmq://127.0.0.1/private/Service2/Service2.svc"
binding="netMsmqBinding"
contract="MyInfrastructure.IService2" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<!--
<serviceAuthenticationManager />
-->
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
收到 HTTP Post Service1 时执行以下操作:
StreamReader sr = new StreamReader(formData);
string str = sr.ReadToEnd();
var t = HttpUtility.ParseQueryString(str);
Hashtable nvc = new Hashtable();
foreach (string n in t)
{
nvc.Add(n, (string)t[n]);
}
WcfFormMessage formMessage = new WcfFormMessage(nvc);
////create the Service binding
NetMsmqBinding msmq = new NetMsmqBinding("MsmqFormMessageBindingClient");
msmq.Security.Mode = (NetMsmqSecurityMode) MsmqAuthenticationMode.None;
EndpointAddress address = new EndpointAddress("net.msmq://127.0.0.1/private/Service2/Service2.svc");
ChannelFactory<IService2> factory = new ChannelFactory<IFormService>(msmq,address);
IService2 proxy = factory.CreateChannel();
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
proxy.ProcessForm(formMessage);
//do any 'sent to queue logging/updates here
}