Friday, December 17, 2004

Consuming heteregeneous web services

When consuming a web service, you need to create a message that maps to the web service request. Most people's first instinct (having created the message variable) is to head for the Transform shape within their message Construct. Select a source message, select the request message as the map destination, and then get mapping.

Something that has repeatedly cropped up in the newsgroups is when the request message doesn't appear in the drop-down of available messages in the Transform shape wizard. This is usually caused because the available parts in the request message (i.e. the request parameters) are primitive types (string, int, etc.), not complex types. If this is the case you need to use the Message Assignment shape instead, and use the standard "." property notation within the shape expression editor:

MyRequestMsg.Param1 = "X";
MyRequestMsg.Param2 = 1;

So - primitive types use the Assignment shape, complex types use the Transform:

void MyMethod1(string param1); // primitive parts only - use the Assignment shape
void MyMethod2(MyType param1); // complex parts only - use the Transform shape

There is, however, a third, intermediate case, when the method signature contains both:

void MyMethod3(string param1, MyType param2);

In this case, you'll notice that both parts appear in the Assignment expression IntelliSense, suggesting that you need to use this shape, but you need to supply an object of type MyType as the second parameter, which is where it starts to go "off-road".

Turns out that MyType is defined within one of the Reference*.xsd schema created when the web reference is added / updated.

In this mixed scenario, in addition to declaring a message of type MyMethod_request, you will need to declare an additional message of type MyType, by selecting it from the relevant Reference*.xsd (you may have to hunt around a bit if the web service is complicated.)

Within the message Construct shape, you can then use a Transform to create the MyType message with a map, and then an Assignment to assign a value to the string parameter, and the MyType message to the second.

(There may well be other ways to achieve this, but it works for me :-))

2 comments:

Jeff said...

My god, thank you, you don't know how much time I wasted trying to figure this out. You are the man.

Abhishek Doyle said...

Thanks a ton....dude

:)