![](/img/trans.png)
[英]Inter-service Communication Architecture Using WCF, Dependency Injection, and Unit Testing
[英]WCF inter-service messaging
我正在用2個WCF服務構建一個系統。 兩者都是IIS托管的。 目前,它們都駐留在單個VS2010網站應用程序中,並使用Derfault網站在我的本地IIS7(Windows 7)上運行。 我都啟用了net.tcp。
服務1
服務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服務)?
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.