BizTalk Orchestration Publish Host InProcess Wcf Service without IIS 多种供客户端调用方式
BizTalk Orchestration Publish Host In-Process Wcf Service without IIS 多种供客户端调用方式
BizTalk Server 2006 R2开始支持WCF adapter本次Demo用的是BizTalk Server 2010,把一个简单的流程发布成一个WCF服务供客户端调用。
有了wcf-custom adapter解决BizTalk和外部交互必须借助第三方协议进行,比如FTP,MSMQ,HTTP(IIS),database,现在通过BizTalk发布in-process的wcf就可以,变得非常方便简单。
BizTalk流程设计
流程很简单一个双向的接收端口,实现Request-Response的请求;
Deploy到BizTalk Server ,利用 BizTalk WCF Service Publishing Wizard发布WCF服务。
利用BizTalk WCF Service Publishing Wizard发布服务的操作就不说了,只能发布Host在IIS上生成BizTalkServerIsolatedHost Receive Port的配置和一个WCF的接口服务。
发现发布IsolatedHost服务比较麻烦必须安装IIS才可以用,其实WCF Adapter支持Host In-Process,如图
配置In-Process WCF-Custom Receive Location
配置成功了
客户端调用发布的服务
如果根据默认 svcutil.exe http://localhost:1100/service?wsdl 生成的Proxy类和Endpoint config 调用服务基本的代码如下:
// TwoWayAsyncClient client = new TwoWayAsyncClient(); string requestBody= " <ns0:Request xmlns:ns0=\"http://BizTalkExposeWCF.Request\"><Record><Field1>Field1_0</Field1></Record></ns0:Request> " ; // MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(requestBody)); // XmlReader reader = XmlReader.Create(new System.IO.StringReader(requestBody)); // Message request = Message.CreateMessage(MessageVersion.Default, "BizTalkSubmit", reader); // Console.WriteLine(request); // Message response= client.BizTalkSubmit(request);
根据这样的代码肯定会报错 System.NotSupportedException: Specified method is not supported.
报错原因是不知道BizTalk流程的接收端口发布的具体 contract 生成的Proxy里没有。
解决这个问题的办法是使用BizTalk WCF Service Publishing Wizard发布的IIS服务生成的Proxy代理来Call这个服务就可以解决这个问题
BizTalkExposeWCF_FlowProcess_ExposePortClient client = new BizTalkExposeWCF_FlowProcess_ExposePortClient(); // TwoWayAsyncClient client = new TwoWayAsyncClient(); string requestBody= " <ns0:Request xmlns:ns0=\"http://BizTalkExposeWCF.Request\"><Record><Field1>Field1_0</Field1></Record></ns0:Request> " ; // MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(requestBody)); // XmlReader reader = XmlReader.Create(new System.IO.StringReader(requestBody)); // Message request = Message.CreateMessage(MessageVersion.Default, "BizTalkSubmit", reader); // Console.WriteLine(request); // Message response= client.BizTalkSubmit(request); Request request = new Request(); request.Record = new RequestRecord(); request.Record.Field1 = " request " ; Response response = client.Operation_1(request); Console.Write(response.Result.Field); Console.ReadLine(); client.Close();
直接使用http Post调用WCF服务
如果你觉得这么做还是麻烦,那么还有一种最简单的方法来实现交互。直接通过http Post把request message Post进流程并且接收response message
只需要修改一下receive Location配置
客户端使用Fiddler模拟
是不是很简单。
希望对大家有帮助
分类: Biztalk
作者: Leo_wl
出处: http://www.cnblogs.com/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于BizTalk Orchestration Publish Host InProcess Wcf S的详细内容...