ASMX 2.0 - Basic Profile 1.0 Conformance
ASP.NET web services (commonly known as ASMX web services) have been a part of the .NET Framework from the beginning in v1.0 when it was still early days in the web services world. A number of enhancements have been made to ASMX in version 2.0 of the framework and one in particular is aimed at helping developers achieve improved interoperability with other web service platforms.
The original SOAP 1.1 and WSDL 1.1 specifications were very broadly defined and this has made interop a difficult goal. Through a standards organisation called the WS-I, a specification called Basic Profile Version 1.0 (BP) was created that defines a profile or subset of the SOAP and WSDL specs that should be used. By providing a set of rules that narrows the scope of web service implementations there is a greater chance that different platforms can work together successfully. ASMX 2.0 includes checks against all the BP rules to determine if your web service is compliant.
Existing web services from the 1.0 or 1.1 version of .NET when run with the 2.0 version of the framework will be checked to see if they are BP compliant. A warning will be given on the documentation page if the web service is non-compliant but either way the service will continue to work as it did with previous versions. Any warnings are just for information and can be disabled if you choose. The following file, simple.asmx, demonstrates this:
<%@ WebService Language="C#" Class="SimpleService" %>
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace="urn:simple")]
public class SimpleService {
[WebMethod, <span style="background-color:yellow">SoapRpcMethod</span>]
public string Hello(string s) {
return string.Format("Hello, {0}!",s);
}
}
The Hello method has the SoapRpcMethod attribute causing it to use a SOAP rpc/encoded binding. This is not allowed by the Basic Profile and so the documentation page for the web service gives the warning “This web service does not conform to WS-I Basic Profile v1.0.” The specific BP rule that has been violated is quoted together with a recommendation for what to do to make the service compliant. If we remove the SoapRpcMethod attribute, the warning goes away and the service conforms.
New web services built for the 2.0 framework can explicitly declare their BP compliance using the ComformanceClaims property of the WebServiceBinding attribute:
<%@ WebService Language="C#" Class="SimpleService" %>
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace="urn:simple")]
<span style="background-color:yellow">[WebServiceBinding(ConformanceClaims=WsiClaims.BP10,EmitConformanceClaims=true)]</span>
public class SimpleService {
[WebMethod]
public string Hello(string s) {
return string.Format("Hello, {0}!",s);
}
}
The WebServiceBinding attribute adds a claim for conformance to the Basic Profile 1.0. The EmitConfirmanceClaims property exposes this claim in a machine readable way by including the following XML as part of the WSDL for the web service:
<wsdl:documentation>
<wsi:Claim conformsTo="http://ws-i.org/profiles/basic/1.0" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" />
</wsdl:documentation>
Asserting Basic Profile 1.0 conformance using the WebServiceBinding attribute enforces the rules checking. If the service is non-conformant then an exception will be generated rather than the warning if the attribute is not present. This makes sense: you can’t assert conformance and then not achieve it. As with the warning, the exception message tells you which rules weren’t satisfied and suggests how to fix the problem.
As different platforms address conformance to the Basic Profile it will be much easier to build interoperable web services and clients right first time.
Update: This code is written with Beta 1 of .NET 2.0 which uses Basic Profile v1.0. Beta 2 will use the Basic Profile 1.1.