From 12f0fab4a4d59efe6b15fa446a286b070a387016 Mon Sep 17 00:00:00 2001 From: hongdai Date: Mon, 24 Oct 2016 16:53:09 -0700 Subject: [PATCH] Fix test services for addding service reference * We would like to leverge the same test server for WCF connected service testing. --- .../Common/Scenarios/ScenarioTestTypes.cs | 2 +- .../Message/MessageContractCommon.4.1.0.cs | 16 ++++++------- .../Message/MessageContractTests.4.1.0.cs | 23 +++++++++++-------- .../App_code/CompositeType.cs | 2 +- .../DigestServiceAuthorizationManager.cs | 7 ++++++ .../App_code/ReplyBankingData.cs | 2 +- .../App_code/ReplyBankingDataNotWrapped.cs | 10 ++++---- .../App_code/RequestBankingData.cs | 2 +- .../App_code/testhosts/TestServiceHostBase.cs | 8 +++++++ 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/System.Private.ServiceModel/tests/Common/Scenarios/ScenarioTestTypes.cs b/src/System.Private.ServiceModel/tests/Common/Scenarios/ScenarioTestTypes.cs index 42d7f0d0542..1dc687995eb 100644 --- a/src/System.Private.ServiceModel/tests/Common/Scenarios/ScenarioTestTypes.cs +++ b/src/System.Private.ServiceModel/tests/Common/Scenarios/ScenarioTestTypes.cs @@ -1294,7 +1294,7 @@ public XmlMessageContractTestRequest(string message) [MessageContract(WrapperName = "XmlMessageContractTestRequestWithMessageHeader", WrapperNamespace = "http://www.contoso.com/XmlMessageContarctTestMessages", IsWrapped = true)] public partial class XmlMessageContractTestRequestWithMessageHeader { - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = false)] + [MessageHeader(Name = "XmlMessageContractTestRequestWithMessageHeaderMessage", Namespace = "http://www.contoso.com", MustUnderstand = false)] public string Message; public XmlMessageContractTestRequestWithMessageHeader() diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractCommon.4.1.0.cs b/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractCommon.4.1.0.cs index abc21add483..60440b4cd64 100644 --- a/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractCommon.4.1.0.cs +++ b/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractCommon.4.1.0.cs @@ -15,7 +15,6 @@ namespace MessageContractCommon public class MessageContractConstants { // CONSTANTS - public const string wrapperName = "CustomWrapperName"; public const string wrapperNamespace = "http://www.contoso.com"; public const string dateElementName = "Date_of_Request"; public static string dateElementValue = ""; @@ -24,7 +23,6 @@ public class MessageContractConstants public const string customerElementName = "Customer_Name"; public const string customerElementNamespace = "http://www.contoso.com"; public const string customerElementValue = "Michael Jordan"; - public const string extraValuesName = "OutOfBandData"; public const string extraValuesNamespace = "http://www.contoso.com"; } @@ -78,7 +76,7 @@ public interface IMessageContract public class MessageContractTypes { - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "RequestBankingDataWrapper", WrapperNamespace = "http://www.contoso.com")] public class RequestBankingData { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -89,7 +87,7 @@ public class RequestBankingData public int amount; } - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingData { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -100,7 +98,7 @@ public class ReplyBankingData public int amount; } - [MessageContract(IsWrapped = false, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = false)] public class ReplyBankingDataNotWrapped { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -111,7 +109,7 @@ public class ReplyBankingDataNotWrapped public int amount; } - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWithMessageHeaderWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingDataWithMessageHeader { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -120,11 +118,11 @@ public class ReplyBankingDataWithMessageHeader public string accountName; [MessageBodyMember(Order = 2, Name = "Transaction_Amount")] public int amount; - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = true)] + [MessageHeader(Name = "ReplyBankingDataWithMessageHeaderExtraValues", Namespace = "http://www.contoso.com", MustUnderstand = true)] public string extraValues; } - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWithMessageHeaderNotNecessaryUnderstoodWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingDataWithMessageHeaderNotNecessaryUnderstood { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -133,7 +131,7 @@ public class ReplyBankingDataWithMessageHeaderNotNecessaryUnderstood public string accountName; [MessageBodyMember(Order = 2, Name = "Transaction_Amount")] public int amount; - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = false)] + [MessageHeader(Name = "ReplyBankingDataWithMessageHeaderNotNecessaryUnderstoodExtraValue", Namespace = "http://www.contoso.com", MustUnderstand = false)] public string extraValues; } } diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractTests.4.1.0.cs b/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractTests.4.1.0.cs index 16ec534f65f..190db6f4d63 100644 --- a/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractTests.4.1.0.cs +++ b/src/System.Private.ServiceModel/tests/Scenarios/Contract/Message/MessageContractTests.4.1.0.cs @@ -21,8 +21,9 @@ public static void MessageContract_IsWrapped_True() clientProxy.MessageContractRequestReply(requestData); XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector); - Assert.True(reader.LocalName.Equals(MessageContractConstants.wrapperName), - string.Format("reader.LocalName - Expected: {0}, Actual: {1}", MessageContractConstants.wrapperName, reader.LocalName)); + string wrapperName = "ReplyBankingDataWrapper"; + Assert.True(reader.LocalName.Equals(wrapperName), + string.Format("reader.LocalName - Expected: {0}, Actual: {1}", wrapperName, reader.LocalName)); Assert.True(reader.NamespaceURI.Equals(MessageContractConstants.wrapperNamespace), string.Format("reader.NamespaceURI - Expected: {0}, Actual: {1}", MessageContractConstants.wrapperNamespace, reader.NamespaceURI)); @@ -38,7 +39,8 @@ public static void MessageContract_IsWrapped_False() clientProxy.MessageContractRequestReplyNotWrapped(requestData); XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector); - Assert.False(reader.LocalName.Equals(MessageContractConstants.wrapperName), + string wrapperName = "ReplyBankingDataWrapper"; + Assert.False(reader.LocalName.Equals(wrapperName), "When IsWrapped set to false, the message body should not be wrapped with an extra element."); } @@ -52,8 +54,9 @@ public static void MessageBody_Elements_Ordered() clientProxy.MessageContractRequestReply(requestData); XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector); - Assert.True(reader.LocalName.Equals(MessageContractConstants.wrapperName), - string.Format("Unexpected element order (1/5). Expected {0}, Actual: {1}", MessageContractConstants.wrapperName, reader.LocalName)); + string wrapperName = "ReplyBankingDataWrapper"; + Assert.True(reader.LocalName.Equals(wrapperName), + string.Format("Unexpected element order (1/5). Expected {0}, Actual: {1}", wrapperName, reader.LocalName)); reader.Read(); @@ -79,8 +82,8 @@ public static void MessageBody_Elements_Ordered() reader.Read(); // Move to the end tag reader.ReadEndElement(); // Checks that the current content node is an end tag and advances the reader to the next node. - Assert.True(reader.IsStartElement() == false && reader.LocalName.Equals(MessageContractConstants.wrapperName), - string.Format("Unexpected element order (5/5). Expected: {0}, Actual: {1}", MessageContractConstants.wrapperName, reader.LocalName)); + Assert.True(reader.IsStartElement() == false && reader.LocalName.Equals(wrapperName), + string.Format("Unexpected element order (5/5). Expected: {0}, Actual: {1}", wrapperName, reader.LocalName)); } [WcfFact] @@ -123,7 +126,8 @@ public static void MessageHeader_MustUnderstand_True() clientProxy.MessageContractRequestReplyWithMessageHeader(requestData); MessageHeaders headers = MessageContractHelpers.GetHeaders(inspector); - int index = headers.FindHeader(MessageContractConstants.extraValuesName, MessageContractConstants.extraValuesNamespace); + string extraValue = "ReplyBankingDataWithMessageHeaderExtraValues"; + int index = headers.FindHeader(extraValue, MessageContractConstants.extraValuesNamespace); var header = headers[index]; Assert.True(header != null, "There's no header in the message."); @@ -140,7 +144,8 @@ public static void MessageHeader_MustUnderstand_False() clientProxy.MessageContractRequestReplyWithMessageHeaderNotNecessaryUnderstood(requestData); MessageHeaders headers = MessageContractHelpers.GetHeaders(inspector); - int index = headers.FindHeader(MessageContractConstants.extraValuesName, MessageContractConstants.extraValuesNamespace); + string extraValue = "ReplyBankingDataWithMessageHeaderNotNecessaryUnderstoodExtraValue"; + int index = headers.FindHeader(extraValue, MessageContractConstants.extraValuesNamespace); var header = headers[index]; Assert.True(header != null, "There's no header in the message."); diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs index b1a628ffd84..61269cf9e05 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/CompositeType.cs @@ -217,7 +217,7 @@ public XmlMessageContractTestRequest(string message) [MessageContract(WrapperName = "XmlMessageContractTestRequestWithMessageHeader", WrapperNamespace = "http://www.contoso.com/XmlMessageContarctTestMessages", IsWrapped = true)] public partial class XmlMessageContractTestRequestWithMessageHeader { - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = false)] + [MessageHeader(Name = "XmlMessageContractTestRequestWithMessageHeaderMessage", Namespace = "http://www.contoso.com", MustUnderstand = false)] public string Message; public XmlMessageContractTestRequestWithMessageHeader() diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs index e5d9af61813..efde4b2a3b1 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/DigestServiceAuthorizationManager.cs @@ -50,6 +50,13 @@ private bool Authorized(DigestAuthenticationState digestState, OperationContext public override bool CheckAccess(OperationContext operationContext, ref Message message) { + var contractName = operationContext.EndpointDispatcher.ContractName; + if (contractName == "IMetadataExchange" || contractName == "IHttpGetHelpPageAndMetadataContract") + { + // support for MEX + return true; + } + var digestState = new DigestAuthenticationState(operationContext, GetRealm(ref message)); if (!digestState.IsRequestDigestAuth) { diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs index 01536e04ff1..355cad48c65 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingData.cs @@ -8,7 +8,7 @@ namespace WcfService { - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingData { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs index 1d21eb4d487..3d1a41417d5 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/ReplyBankingDataNotWrapped.cs @@ -8,7 +8,7 @@ namespace WcfService { - [MessageContract(IsWrapped = false, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = false)] public class ReplyBankingDataNotWrapped { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -19,7 +19,7 @@ public class ReplyBankingDataNotWrapped public int amount; } - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWithMessageHeaderWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingDataWithMessageHeader { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -28,11 +28,11 @@ public class ReplyBankingDataWithMessageHeader public string accountName; [MessageBodyMember(Order = 2, Name = "Transaction_Amount")] public int amount; - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = true)] + [MessageHeader(Name = "ReplyBankingDataWithMessageHeaderExtraValues", Namespace = "http://www.contoso.com", MustUnderstand = true)] public string extraValues; } - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "ReplyBankingDataWithMessageHeaderNotNecessaryUnderstoodWrapper", WrapperNamespace = "http://www.contoso.com")] public class ReplyBankingDataWithMessageHeaderNotNecessaryUnderstood { [MessageBodyMember(Order = 1, Name = "Date_of_Request")] @@ -41,7 +41,7 @@ public class ReplyBankingDataWithMessageHeaderNotNecessaryUnderstood public string accountName; [MessageBodyMember(Order = 2, Name = "Transaction_Amount")] public int amount; - [MessageHeader(Name = "OutOfBandData", Namespace = "http://www.contoso.com", MustUnderstand = false)] + [MessageHeader(Name = "ReplyBankingDataWithMessageHeaderNotNecessaryUnderstoodExtraValue", Namespace = "http://www.contoso.com", MustUnderstand = false)] public string extraValues; } } diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs index df357d23486..4c164289dab 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/RequestBankingData.cs @@ -8,7 +8,7 @@ namespace WcfService { - [MessageContract(IsWrapped = true, WrapperName = "CustomWrapperName", WrapperNamespace = "http://www.contoso.com")] + [MessageContract(IsWrapped = true, WrapperName = "RequestBankingDataWrapper", WrapperNamespace = "http://www.contoso.com")] public class RequestBankingData { #pragma warning disable 0649 // fields not assigned to statically diff --git a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs index 056442c8e42..db8ce8c8618 100644 --- a/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs +++ b/src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TestServiceHostBase.cs @@ -68,6 +68,14 @@ protected override void ApplyConfiguration() MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); } + + if (baseAddress.Scheme == Uri.UriSchemeNetTcp) + { + mexBehavior.HttpGetEnabled = false; + this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, + MetadataExchangeBindings.CreateMexTcpBinding(), + "mex"); + } } } }