Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test services for addding service reference #1611

Merged
merged 1 commit into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace MessageContractCommon
public class MessageContractConstants
{
// CONSTANTS
public const string wrapperName = "CustomWrapperName";
public const string wrapperNamespace = "http://www.contoso.com";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you have just changed the constant here instead of removing it? The rest of the tests use these constants to avoid duplicating strings inside the tests. Not blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to have a const defined in the common code for wrapper name as it could be different per test, although it happens to be the same for the existing 3 tests.

public const string dateElementName = "Date_of_Request";
public static string dateElementValue = "";
Expand All @@ -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";
}

Expand Down Expand Up @@ -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
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[No change required -- observation only] It's too bad the original test didn't use the same constants in MessageContractConstants for these attribute named parameters. It would have eliminated so much string duplication scattered in the contracts and tests.

[MessageBodyMember(Order = 1, Name = "Date_of_Request")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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.");
}

Expand All @@ -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();

Expand All @@ -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]
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down