Permalink
Browse files

[WCF]: Implement and improve missing WsdlExporter pieces.

* We now export simple <wsp:Policy>, currently supporting only
  those elements that WsdlImporter can import.

  WsdlImporter:
  cdc98db

* Implement `MetadataExporter.Errors' and use it for error
  reporting.

* Fixed WsdlExporter's caching to correclty deal with duplicate
  ExportContract() and ExportEndpoint() calls.

* Emit <soap12:operation> depending on the binding's MessageVersion.
  (FIXME: I didn't implement soap faults yet).

* MetadataTests: Check whether the policy elements are correct.

* MetadataTests: Add test containing simple [OperationContract] method
  for http and net.tcp; checks the <soap:operation> / <soap12:operation>
  elements.

* New test to check WsdlExporter's behavior regarding duplicate
  contracts and endpoints.

* ConnectionOrientedTransportBindingElement.cs, CustomBindingTests.cs,
  HttpTransportBindingElementTest.cs: Added test for custom message
  encodings.
  • Loading branch information...
1 parent ca6f897 commit c1b505c0cafb73857c092accc4e9cef2230bf97d @baulig baulig committed Dec 5, 2012
Showing with 1,493 additions and 381 deletions.
  1. +4 −4 mcs/class/System.ServiceModel/System.ServiceModel.Channels/BinaryMessageEncodingBindingElement.cs
  2. +41 −4 ...ass/System.ServiceModel/System.ServiceModel.Channels/ConnectionOrientedTransportBindingElement.cs
  3. +51 −8 mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpTransportBindingElement.cs
  4. +4 −2 mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpsTransportBindingElement.cs
  5. +4 −4 mcs/class/System.ServiceModel/System.ServiceModel.Channels/MtomMessageEncodingBindingElement.cs
  6. +39 −0 mcs/class/System.ServiceModel/System.ServiceModel.Channels/PolicyImportHelper.cs
  7. +8 −3 mcs/class/System.ServiceModel/System.ServiceModel.Channels/SslStreamSecurityBindingElement.cs
  8. +0 −4 mcs/class/System.ServiceModel/System.ServiceModel.Channels/TextMessageEncodingBindingElement.cs
  9. +65 −0 mcs/class/System.ServiceModel/System.ServiceModel.Channels/TransportBindingElement.cs
  10. +19 −3 mcs/class/System.ServiceModel/System.ServiceModel.Channels/WindowsStreamSecurityBindingElement.cs
  11. +8 −3 mcs/class/System.ServiceModel/System.ServiceModel.Description/CustomPolicyConversionContext.cs
  12. +37 −1 mcs/class/System.ServiceModel/System.ServiceModel.Description/MetadataExporter.cs
  13. +227 −85 mcs/class/System.ServiceModel/System.ServiceModel.Description/WsdlExporter.cs
  14. +1 −0 mcs/class/System.ServiceModel/System.ServiceModel_test.dll.sources
  15. +359 −102 mcs/class/System.ServiceModel/Test/MetadataTests/BindingTestAssertions.cs
  16. +243 −0 mcs/class/System.ServiceModel/Test/MetadataTests/ExportTests.cs
  17. +18 −0 mcs/class/System.ServiceModel/Test/MetadataTests/ImportTests.cs
  18. +0 −47 mcs/class/System.ServiceModel/Test/MetadataTests/ImportTests_CreateMetadata.cs
  19. +0 −48 mcs/class/System.ServiceModel/Test/MetadataTests/ImportTests_RoundTrip.cs
  20. +55 −32 mcs/class/System.ServiceModel/Test/MetadataTests/MetadataSamples.cs
  21. +3 −0 mcs/class/System.ServiceModel/Test/MetadataTests/MetadataTests.csproj
  22. +55 −0 mcs/class/System.ServiceModel/Test/MetadataTests/Resources/BasicHttp_Operation.xml
  23. +67 −0 mcs/class/System.ServiceModel/Test/MetadataTests/Resources/NetTcp_Operation.xml
  24. +0 −31 mcs/class/System.ServiceModel/Test/MetadataTests/TestContext.cs
  25. +74 −0 ...m.ServiceModel/Test/System.ServiceModel.Channels/ConnectionOrientedTransportBindingElementTest.cs
  26. +37 −0 mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/CustomBindingTest.cs
  27. +74 −0 mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/HttpTransportBindingElementTest.cs
@@ -138,18 +138,18 @@ public override MessageEncoderFactory
throw new NotImplementedException ();
}
- [MonoTODO]
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
WsdlEndpointConversionContext context)
{
- throw new NotImplementedException ();
}
- [MonoTODO]
void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter,
PolicyConversionContext context)
{
- throw new NotImplementedException ();
+ PolicyAssertionCollection assertions = context.GetBindingAssertions ();
+ XmlDocument doc = new XmlDocument ();
+
+ assertions.Add (doc.CreateElement ("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
}
#endif
}
@@ -1,10 +1,12 @@
//
// ConnectionOrientedTransportBindingElement.cs
//
-// Author:
+// Authors:
// Atsushi Enomoto <atsushi@ximian.com>
+// Martin Baulig <martin.baulig@xamarin.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
+// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -31,12 +33,13 @@
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;
+using WS = System.Web.Services.Description;
namespace System.ServiceModel.Channels
{
[MonoTODO]
public abstract class ConnectionOrientedTransportBindingElement
- : TransportBindingElement, IPolicyExportExtension
+ : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
{
int connection_buf_size = 0x2000, max_buf_size = 0x10000,
max_pending_conn = 10, max_pending_accepts = 1;
@@ -138,6 +141,37 @@ public override T GetProperty<T> (BindingContext context)
return base.GetProperty<T> (context);
}
+ void IWsdlExportExtension.ExportContract (WsdlExporter exporter,
+ WsdlContractConversionContext context)
+ {
+ ;
+ }
+
+ void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
+ WsdlEndpointConversionContext context)
+ {
+ var soap_binding = new WS.Soap12Binding ();
+ soap_binding.Transport = "http://schemas.microsoft.com/soap/tcp";
+ soap_binding.Style = WS.SoapBindingStyle.Document;
+ context.WsdlBinding.Extensions.Add (soap_binding);
+
+ var address = context.Endpoint.Address;
+ var uri = address.Uri.AbsoluteUri;
+
+ var soap_address = new WS.Soap12AddressBinding ();
+ soap_address.Location = uri;
+ context.WsdlPort.Extensions.Add (soap_address);
+
+ var doc = new XmlDocument ();
+ var endpoint_ref = doc.CreateElement (
+ "EndpointReference", AddressingVersion.WSAddressing10.Namespace);
+ var endpoint_addr = doc.CreateElement (
+ "Address", AddressingVersion.WSAddressing10.Namespace);
+ endpoint_addr.InnerText = uri;
+ endpoint_ref.AppendChild (endpoint_addr);
+ context.WsdlPort.Extensions.Add (endpoint_ref);
+ }
+
void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext context)
{
if (exporter == null)
@@ -148,8 +182,11 @@ void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConve
PolicyAssertionCollection assertions = context.GetBindingAssertions ();
XmlDocument doc = new XmlDocument ();
- assertions.Add (doc.CreateElement ("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));
- assertions.Add (doc.CreateElement ("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
+ var messageEncodingElement = ExportAddressingPolicy (context);
+ if (messageEncodingElement == null)
+ assertions.Add (doc.CreateElement (
+ "msb", "BinaryEncoding",
+ "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
transfer_mode == TransferMode.StreamedResponse)
@@ -38,6 +38,7 @@
using System.ServiceModel.Channels.Http;
#endif
using System.ServiceModel.Description;
+using WS = System.Web.Services.Description;
using System.Xml;
namespace System.ServiceModel.Channels
@@ -278,18 +279,52 @@ public override T GetProperty<T> (BindingContext context)
PolicyAssertionCollection assertions = context.GetBindingAssertions ();
XmlDocument doc = new XmlDocument ();
- assertions.Add (doc.CreateElement ("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));
+ ExportAddressingPolicy (context);
switch (auth_scheme) {
- case AuthenticationSchemes.Basic:
- case AuthenticationSchemes.Digest:
- case AuthenticationSchemes.Negotiate:
- case AuthenticationSchemes.Ntlm:
- assertions.Add (doc.CreateElement ("http",
+ case AuthenticationSchemes.Basic:
+ case AuthenticationSchemes.Digest:
+ case AuthenticationSchemes.Negotiate:
+ case AuthenticationSchemes.Ntlm:
+ assertions.Add (doc.CreateElement ("http",
auth_scheme.ToString () + "Authentication",
"http://schemas.microsoft.com/ws/06/2004/policy/http"));
- break;
+ break;
}
+
+ var transportProvider = this as ITransportTokenAssertionProvider;
+ if (transportProvider != null) {
+ var token = transportProvider.GetTransportTokenAssertion ();
+ assertions.Add (CreateTransportBinding (token));
+ }
+ }
+
+ XmlElement CreateTransportBinding (XmlElement transportToken)
+ {
+ var doc = new XmlDocument ();
+ var transportBinding = doc.CreateElement (
+ "sp", "TransportBinding", PolicyImportHelper.SecurityPolicyNS);
+
+ var token = doc.CreateElement (
+ "sp", "TransportToken", PolicyImportHelper.SecurityPolicyNS);
+ PolicyImportHelper.AddWrappedPolicyElement (token, transportToken);
+
+ var algorithmSuite = doc.CreateElement (
+ "sp", "AlgorithmSuite", PolicyImportHelper.SecurityPolicyNS);
+ var basic256 = doc.CreateElement (
+ "sp", "Basic256", PolicyImportHelper.SecurityPolicyNS);
+ PolicyImportHelper.AddWrappedPolicyElement (algorithmSuite, basic256);
+
+ var layout = doc.CreateElement (
+ "sp", "Layout", PolicyImportHelper.SecurityPolicyNS);
+ var strict = doc.CreateElement (
+ "sp", "Strict", PolicyImportHelper.SecurityPolicyNS);
+ PolicyImportHelper.AddWrappedPolicyElement (layout, strict);
+
+ PolicyImportHelper.AddWrappedPolicyElements (
+ transportBinding, token, algorithmSuite, layout);
+
+ return transportBinding;
}
[MonoTODO]
@@ -303,7 +338,15 @@ public override T GetProperty<T> (BindingContext context)
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
WsdlEndpointConversionContext context)
{
- throw new NotImplementedException ();
+ var soap_binding = new WS.SoapBinding ();
+ soap_binding.Transport = WS.SoapBinding.HttpTransport;
+ soap_binding.Style = WS.SoapBindingStyle.Document;
+ context.WsdlBinding.Extensions.Add (soap_binding);
+
+ var soap_address = new WS.SoapAddressBinding ();
+ soap_address.Location = context.Endpoint.Address.Uri.AbsoluteUri;
+
+ context.WsdlPort.Extensions.Add (soap_address);
}
#endif
}
@@ -84,10 +84,12 @@ public override BindingElement Clone ()
}
#if !NET_2_1
- [MonoTODO]
public XmlElement GetTransportTokenAssertion ()
{
- throw new NotImplementedException ();
+ var doc = new XmlDocument ();
+ var token = doc.CreateElement ("sp", "HttpsToken", PolicyImportHelper.SecurityPolicyNS);
+ token.SetAttribute ("RequireClientCertificate", req_cli_cert ? "true" : "false");
+ return token;
}
// overriden only in full profile
@@ -145,18 +145,18 @@ public override MessageEncoderFactory
throw new NotImplementedException ();
}
- [MonoTODO]
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
WsdlEndpointConversionContext context)
{
- throw new NotImplementedException ();
}
- [MonoTODO]
public void ExportPolicy (MetadataExporter exporter,
PolicyConversionContext context)
{
- throw new NotImplementedException ();
+ PolicyAssertionCollection assertions = context.GetBindingAssertions ();
+ XmlDocument doc = new XmlDocument ();
+
+ assertions.Add (doc.CreateElement ("wsoma", "OptimizedMimeSerialization", "http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"));
}
}
}
@@ -42,6 +42,8 @@ internal static class PolicyImportHelper {
internal const string FramingPolicyNS = "http://schemas.microsoft.com/ws/2006/05/framing/policy";
internal const string NetBinaryEncodingNS = "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1";
+ internal const string WSSecurityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
+
internal static XmlElement GetTransportBindingPolicy (PolicyAssertionCollection collection)
{
return FindAndRemove (collection, "TransportBinding", SecurityPolicyNS);
@@ -219,6 +221,43 @@ internal static List<XmlElement> GetPolicyElements (XmlElement root, out bool er
importer.AddWarning ("Did not find required policy element `{0}'", name);
return element;
}
+
+ internal static XmlElement WrapPolicy (XmlElement element)
+ {
+ var policy = element.OwnerDocument.CreateElement ("wsp", "Policy", PolicyNS);
+ policy.AppendChild (element);
+ return policy;
+ }
+
+ //
+ // Add a single element, wrapping it inside <wsp:Policy>
+ //
+ internal static void AddWrappedPolicyElement (XmlElement root, XmlElement element)
+ {
+ if (root.OwnerDocument != element.OwnerDocument)
+ element = (XmlElement)root.OwnerDocument.ImportNode (element, true);
+ if (!element.NamespaceURI.Equals (PolicyNS) || !element.LocalName.Equals ("Policy"))
+ element = WrapPolicy (element);
+ root.AppendChild (element);
+ }
+
+ //
+ // Add multiple elements, wrapping them inside a single <wsp:Policy>
+ //
+ internal static void AddWrappedPolicyElements (XmlElement root, params XmlElement[] elements)
+ {
+ var policy = root.OwnerDocument.CreateElement ("wsp", "Policy", PolicyNS);
+ root.AppendChild (policy);
+
+ foreach (var element in elements) {
+ XmlElement imported;
+ if (root.OwnerDocument != element.OwnerDocument)
+ imported = (XmlElement)root.OwnerDocument.ImportNode (element, true);
+ else
+ imported = element;
+ policy.AppendChild (element);
+ }
+ }
}
}
@@ -82,7 +82,10 @@ public StreamUpgradeProvider BuildServerStreamUpgradeProvider (BindingContext co
[MonoTODO]
public XmlElement GetTransportTokenAssertion ()
{
- throw new NotImplementedException ();
+ var doc = new XmlDocument ();
+ var element = doc.CreateElement (
+ "msf", "SslTransportSecurity", PolicyImportHelper.FramingPolicyNS);
+ return element;
}
[MonoTODO]
@@ -130,9 +133,11 @@ public override T GetProperty<T> (BindingContext context)
[MonoTODO]
void IPolicyExportExtension.ExportPolicy (
MetadataExporter exporter,
- PolicyConversionContext policyContext)
+ PolicyConversionContext context)
{
- throw new NotImplementedException ();
+ var token = GetTransportTokenAssertion ();
+ var transportBinding = TransportBindingElement.CreateTransportBinding (token);
+ context.GetBindingAssertions ().Add (transportBinding);
}
#endregion
}
@@ -159,18 +159,14 @@ public override MessageEncoderFactory
throw new NotImplementedException ();
}
- [MonoTODO]
void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter,
WsdlEndpointConversionContext context)
{
- throw new NotImplementedException ();
}
- [MonoTODO]
void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter,
PolicyConversionContext context)
{
- throw new NotImplementedException ();
}
#endif
}
Oops, something went wrong. Retry.

3 comments on commit c1b505c

@marek-safar
Member

This broke some 2.0 tests

@baulig
Member
baulig commented on c1b505c Dec 6, 2012

Are you talking about this:

InvalidOperationException in at MonoTests.System.ServiceModel.MetadataTests.MetadataSamples.GetMetadataByName (System.String name) [0x00000] in <filename unknown>:0 ?

These are new tests that I added and there's some kind of a compilation / setup issue - the test can't find the .xml file that it's supposed to load for testing.

Don't know why this is happening, a make check works just fine for me and the System.ServiceModel-2 and System.ServiceModel-4 tests are also green on buildbot.

However, I just saw the problem when running make run-test PROFILE=<whatever> on my machine.

I'll have a look.

@baulig
Member
baulig commented on c1b505c Dec 7, 2012

Fixed; #if NET_4_5 was missing.

Please sign in to comment.