简体   繁体   中英

WCF inter-service messaging

I am building a system with 2 WCF Services. Both are IIS Hosted. At the moment they both reside in a single VS2010 website app, running on my local IIS7 (Windows 7) using the Derfault Website. I have enabled net.tcp on both.

Service1

  • accepts HTTP posts using webHttpBinding
  • wraps the data in a serializable composite object
  • sends the composite object to Service2 (we hope) using netMsmqBinding

Service2

  • 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

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.

Questions:

  1. Am I doing this correctly (is there something wrong in the structure, web.config or code)?

  2. When done properly in VS Debug, should Service1's

    proxy.ProcessForm(formMessage);

hit breakpoints in my Service2 code, or is there another way to hande Service2 debug (ala windows services for example)?

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:

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. Type the machine name in there, even if it is local.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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