繁体   English   中英

WCF服务间消息传递

[英]WCF inter-service messaging

我正在用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是否由于其位置而错过了该消息,但是根据我阅读的内容,它似乎是-我没有遇到任何提及此队列创建行为的内容。

问题:

  1. 我这样做是否正确(结构,web.config或代码中是否有错误)?

  2. 在VS Debug中正确完成后,应该使用Service1

    proxy.ProcessForm(formMessage);

击中我的Service2代码中的断点,还是还有另一种方法来处理Service2调试(例如ala Windows服务)?

Service1 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
}

我敢打赌,您的问题与配置中的127.0.0.1有关。 即使在本地也要在其中键入计算机名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM