Skip to content

Commit

Permalink
Fix test services for addding service reference
Browse files Browse the repository at this point in the history
* We would like to leverge the same test server for WCF connected service
testing.
  • Loading branch information
hongdai committed Oct 24, 2016
1 parent d92f922 commit 12f0fab
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
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";
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
{
[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

0 comments on commit 12f0fab

Please sign in to comment.