简体   繁体   English

WCF服务间消息传递

[英]WCF inter-service messaging

I am building a system with 2 WCF Services. 我正在用2个WCF服务构建一个系统。 Both are IIS Hosted. 两者都是IIS托管的。 At the moment they both reside in a single VS2010 website app, running on my local IIS7 (Windows 7) using the Derfault Website. 目前,它们都驻留在单个VS2010网站应用程序中,并使用Derfault网站在我的本地IIS7(Windows 7)上运行。 I have enabled net.tcp on both. 我都启用了net.tcp。

Service1 服务1

  • accepts HTTP posts using webHttpBinding 使用webHttpBinding接受HTTP帖子
  • wraps the data in a serializable composite object 将数据包装在可序列化的复合对象中
  • sends the composite object to Service2 (we hope) using netMsmqBinding 使用netMsmqBinding将复合对象发送到Service2(我们希望)

Service2 服务2

  • receives said message and does something with it 收到上述消息并对其进行处理

Service 1 works as expected, however instead of placing the message on the configured Private Queue, our code is creating a new Queue under "Outgoing Queues" with the handle 服务1可以按预期工作,但是我们的代码不是将消息放置在已配置的专用队列上,而是使用句柄在“传出队列”下创建一个新队列。

DIRECT=TCP:127.0.0.1\private$\Service2/Service2.svc
note the forward slash

Of course Service2 never sees the message - this is the first time I have attempted this structure so I am not certain that Service2 misses the message because of its location, but based on what I have read it would seem so - I have not come across anything mentioning this Queue-creation behaviour. 当然,Service2从来没有看到该消息-这是我第一次尝试这种结构,因此我不确定Service2是否由于其位置而错过了该消息,但是根据我阅读的内容,它似乎是-我没有遇到任何提及此队列创建行为的内容。

Questions: 问题:

  1. Am I doing this correctly (is there something wrong in the structure, web.config or code)? 我这样做是否正确(结构,web.config或代码中是否有错误)?

  2. When done properly in VS Debug, should Service1's 在VS Debug中正确完成后,应该使用Service1

    proxy.ProcessForm(formMessage); proxy.ProcessForm(formMessage);

hit breakpoints in my Service2 code, or is there another way to hande Service2 debug (ala windows services for example)? 击中我的Service2代码中的断点,还是还有另一种方法来处理Service2调试(例如ala Windows服务)?

Service1 Web.Config 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>

On Receipt of an HTTP Post Service1 executes the following: 收到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
}

I am ready to bet that your problem is related to 127.0.0.1 in your config. 我敢打赌,您的问题与配置中的127.0.0.1有关。 Type the machine name in there, even if it is local. 即使在本地也要在其中键入计算机名称。

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

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