深入biztalk消费Web services

【转】

消费Web services允许把现有的Web services加入到业务流程,可以在一个orchestration整合进多个Web services

可以在orchestrationWeb ports消费(调用)Web service,为了在orchestration调用一个Web service,需要建立一个Web port和构造一个Web messages

 

本文以一个比较典型的实例来说明biztalk如何消费一个web services,深入分析biztalk消费web services的一些内部机制。

 

一、  Web services

有一个Web services,很简单,代码如下:

[WebService(Namespace = "http://chnking.com/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class SAMPLEService : System.Web.Services.WebService

{

    [WebMethod]

    public string[] TwoWayMethod(float a,Person person)

    {

        return new string[] { "1", "2", "3","4" };

    }

}

public class Person

{

    public string firstname;

    public string lastname;

    public Contact contact;

}

public class Contact

{

    public string telpohone;

    public string fax;

    public string address;

    public int postalcode;

}

 

1、 TwoWayMethod方法

方法签名:public string[] TwoWayMethod(float a,Person person)

有两个输入参数:简单类型float 和自定义的类PersonPerson类有三个公开字段,其中有一个字段的类型是自定义类型ContactContact类又包括四个公开字段

返回参数为一个字符串的数组。

2、 查看web servicesWSDL

一个web services要被其它应用调用,就必须告诉其它应用如何去调用web services中的webmethod,比如这个web services中包含哪些可以调用的方法,每个方法的方法签名是怎样的,方法是用的输入输出参数的类型又是什么等等,这些都是通过web servicesWSDL来进行描述的。

要查看一个web servicesWSDL可以向web services所在的asmx文件的URL发送http请求,并附带?wsdl参数即可,比如:http://biztalkr2:81/WSTest/Service1.asmx?WSDL

来查看一下上面这个web servicesWSDL中跟TwoWayMethod相关的部分:clip_image001

Figue 1. WSDL中跟TwoWayMethod相关的部分

 

这个WSDL的结构需要按照从下面往上面的顺序看。

2.1.    portType标签

portType标签用来描述整个的web servicesportTypename属性即为这个web services类的类名。这个标签下包含了所有的可用方法,每个operation标签表示一个方法。

2.2.    operation标签

每一个operation标签表示web services里的一个webmethod方法,operation标签的name属性是这个webmethod的方法名。

2.3.    Inputoutput标签

Inputoutput标签分别表示一个operationwebmethod方法)的输入和输出的参数集合,这里叫做消息,不管输入参数有几个,每个参数有多么复杂,只有一个表示这些输入参数的消息,就是input标签的message属性表示的那个消息。对于输出消息也一样。

2.4.    Message标签

方法的输入输出参数都用一个消息来表示,message标签表示一个这样的消息,message标签按下面有个part标签,用来具体指示这个消息在schema中的类型,类型以element形式表现出来,即part标签的element属性指定的那个element

对于输入参数消息,part标签的element属性命名同webmethod方法名。

对于输出参数消息,part标签的element属性命名同webmethod方法名 + response

表示类型的element都被集中放置在types标签内。

2.5.    types标签

此标签用来描述所有webmethod所要用到的类型,都以element来描述类型。比如:

public string[] TwoWayMethod(float a,Person person)

这个webmethod的输入参数有两个:float a,Person person,在WSDL的中的类型表现是这样的:

<s:element name="TwoWayMethod">

<s:complexType>

<s:sequence>

      <s:element minOccurs="1" maxOccurs="1" name="a" type="s:float" />

      <s:element minOccurs="0" maxOccurs="1" name="person" type="tns:Person" />

    s:sequence>

  s:complexType>