Monday, January 23, 2006

Customizing the WSDL generated by the
‘BizTalk Webservice Publishing Wizard’

Exposing BizTalk interfaces as webservices is very easy using the ‘BizTalk Webservice Publishing Tool’. In almost all cases this tool generates a correct functioning web service which does not need any code modification.

However, there are situations where tweaking the code of the generated web service is necessary. Recently I needed two different BizTalk interfaces to expose the exact same WSDL. Because the two interfaces had different names for namespaces and artifacts, the generated webservices and WSDL were not the same.

You can solve this by using the SoapExtensionReflector. The BizTalk Webservice Publishing Wizard generates a class called ‘WsdlExtensions.cs’ for every webservice that is generated. By including this file in the generated VS.Net webservice project and adding the type in the 'soapExtensionReflectorTypes' section of the web.config (see header comments of
WsdlExtensions.cs), you’re able to control the generated WSDL for the webservice.

By default this file is generated with code for XML schema replacement in the WSDL, but you can use this to change other parts. For example, to override the SOAP service name, you can use:

public override void ReflectMethod()

{

    ProtocolReflector reflector = this.ReflectionContext;

    reflector.Service.Name = "MyNewServiceName";

}




After recompiling the web service the service name in the WSDL is changed to the new value.

1 comment:

Nitin said...

Hello,
I have a web service which takes a message of a particular schema type as its input. This is a complicated schema. When I run the web service wizard, it generates very long names for the schema elements. Is there a way to use an alias of sort for these schema elements so that I can use convenient short names?
Thanks
-N