1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
|
//
// WsdlExporterTest.cs
//
// Author:
// Ankit Jain <JAnkit@novell.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE && !XAMMAC_4_5
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using NUnit.Framework;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Web.Services;
using WSServiceDescription = System.Web.Services.Description.ServiceDescription;
using WSMessage = System.Web.Services.Description.Message;
using WSBinding = System.Web.Services.Description.Binding;
using QName = System.Xml.XmlQualifiedName;
using SMMessage = System.ServiceModel.Channels.Message;
using System.Xml;
using System.Web.Services.Description;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Reflection;
namespace MonoTests.System.ServiceModel.Description
{
[TestFixture]
public class WsdlExporterTest
{
[Test]
[Category ("NotWorking")]
public void Ctor1 ()
{
WsdlExporter we = new WsdlExporter ();
Assert.IsNotNull (we.GetGeneratedMetadata ());
Assert.IsNotNull (we.GeneratedWsdlDocuments, "#c1");
Assert.AreEqual (0, we.GeneratedWsdlDocuments.Count, "#c2");
Assert.IsNotNull (we.GeneratedXmlSchemas, "#c3");
Assert.AreEqual (0, we.GeneratedXmlSchemas.Count, "#c4");
}
[Test]
public void ExportEndpointTest ()
{
WsdlExporter we = new WsdlExporter ();
ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
se.Binding = new BasicHttpBinding ();
se.Address = new EndpointAddress ("http://localhost:8080");
//TEST Invalid name: 5se.Name = "Service#1";
//se.Name = "Service0";
//se.ListenUri = new Uri ("http://localhost:8080/svc");
we.ExportEndpoint (se);
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (6, ms.MetadataSections.Count);
CheckContract_IEchoService (ms, "#eet01");
WSServiceDescription sd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest");
CheckServicePort (GetService (sd, "service", "ExportEndpointTest"),
"BasicHttpBinding_IEchoService", new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
"http://localhost:8080/", "#eet02");
CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
"Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet03");
}
[Test]
public void ExportEndpointTest2 ()
{
WsdlExporter we = new WsdlExporter ();
ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService2)));
se.Binding = new BasicHttpBinding ();
se.Address = new EndpointAddress ("http://localhost:8080");
we.ExportEndpoint (se);
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (5, ms.MetadataSections.Count);
WSServiceDescription sd = ms.MetadataSections [0].Metadata as WSServiceDescription;
CheckContract_IEchoService2 (ms, "#eet20");
CheckServicePort (GetService (GetServiceDescription (ms, "http://tempuri.org/", "#eet21"), "service", "ExportEndpointTest"),
"BasicHttpBinding_ThisIsEchoService", new XmlQualifiedName ("BasicHttpBinding_ThisIsEchoService", "http://tempuri.org/"),
"http://localhost:8080/", "#eet22");
CheckBasicHttpBinding (sd, "BasicHttpBinding_ThisIsEchoService",
new XmlQualifiedName ("ThisIsEchoService", "http://tempuri.org/"),
"Echo", "http://tempuri.org/ThisIsEchoService/Echo", true, true, "#eet03");
//FIXME: CheckXmlSchema
}
[Test]
public void ExportEndpointTest3 ()
{
WsdlExporter we = new WsdlExporter ();
/*ContractDescription contract =*/ ContractDescription.GetContract (typeof (IEchoService2));
ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService2)));
se.Binding = new BasicHttpBinding ();
se.Address = new EndpointAddress ("http://localhost:8080");
we.ExportEndpoint (se);
se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
se.Binding = new BasicHttpBinding ();
se.Address = new EndpointAddress ("http://somehost");
we.ExportEndpoint (se);
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (7, ms.MetadataSections.Count);
Service svc = GetService (
GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest"),
"service", "ExportEndpointTest");
CheckContract_IEchoService (ms, "#eet31");
CheckServicePort (svc, "BasicHttpBinding_IEchoService",
new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
"http://somehost/", "#eet32");
CheckContract_IEchoService2 (ms, "#eet33");
CheckServicePort (svc, "BasicHttpBinding_ThisIsEchoService",
new XmlQualifiedName ("BasicHttpBinding_ThisIsEchoService", "http://tempuri.org/"),
"http://localhost:8080/", "#eet34");
WSServiceDescription sd = ms.MetadataSections [0].Metadata as WSServiceDescription;
CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
"Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet35");
CheckBasicHttpBinding (sd, "BasicHttpBinding_ThisIsEchoService", new XmlQualifiedName ("ThisIsEchoService", "http://tempuri.org/"),
"Echo", "http://tempuri.org/ThisIsEchoService/Echo", true, true, "#eet36");
//FIXME: CheckXmlSchema
}
[Test]
public void ExportContractInvalid1 ()
{
WsdlExporter we = new WsdlExporter ();
we.ExportContract (ContractDescription.GetContract (typeof (IEchoService2)));
//Duplicate contract QNames not allowed
ExportContractExpectException (we, ContractDescription.GetContract (typeof (IEchoService2)),
typeof (ArgumentException), "ExportContractInvalid1");
}
[Test]
public void ExportContractInvalid2 ()
{
WsdlExporter we = new WsdlExporter ();
we.ExportContract (ContractDescription.GetContract (typeof (IEchoService2)));
//Invalid as IEchoService3.Echo is http://tempuri.org/Echo message which has already been exported
//Even though, the service name is different
ExportContractExpectException (we, ContractDescription.GetContract (typeof (IEchoService3)),
typeof (InvalidOperationException), "ExportContractInvalid2");
}
[Test]
public void ExportContract1 ()
{
WsdlExporter we = new WsdlExporter ();
we.ExportContract (ContractDescription.GetContract (typeof (IEchoService)));
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (5, ms.MetadataSections.Count);
CheckContract_IEchoService (ms, "ExportContract1");
}
[Test]
public void ExportContract2 ()
{
WsdlExporter we = new WsdlExporter ();
we.ExportContract (ContractDescription.GetContract (typeof (IFoo1)));
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (5, ms.MetadataSections.Count);
}
[Test]
public void ExportContract2a ()
{
WsdlExporter we = new WsdlExporter ();
we.ExportContract (ContractDescription.GetContract (typeof (IFoo1)));
//IFoo1a.Op1 is the same operations as IFoo1.Op1, so cant be exported
//the message element for both is the same
//(Compared by names not signature)
ExportContractExpectException (we, ContractDescription.GetContract (typeof (IFoo1a)),
typeof (InvalidOperationException), "ExportContract2a");
}
[Test]
[Category ("NotWorking")]
// System.Xml.Schema.XmlSchemaException : XmlSchema error: Named item
// http://schemas.datacontract.org/2004/07/System.Reflection:ArrayOfTypeInfo was already contained
// in the schema object table. Consider setting MONO_STRICT_MS_COMPLIANT to 'yes' to mimic
// MS implementation. Related schema item SourceUri: , Line 0, Position 0.
public void ExportMessageContract ()
{
WsdlExporter we = new WsdlExporter ();
ContractDescription cd = ContractDescription.GetContract (typeof (IFoo2));
we.ExportContract (cd);
}
[Test]
[Category ("NotWorking")]
//FIXME: One check not working, BeginGetResult
public void ExportMexContract ()
{
WsdlExporter we = new WsdlExporter ();
ContractDescription cd = ContractDescription.GetContract (typeof (IMetadataExchange));
we.ExportContract (cd);
MetadataSet ms = we.GetGeneratedMetadata ();
WSServiceDescription sd = GetServiceDescription (ms, "http://schemas.microsoft.com/2006/04/mex", "ExportMexContract");
CheckMessage (sd, "IMetadataExchange_Get_InputMessage", "request", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc0");
CheckMessage (sd, "IMetadataExchange_Get_OutputMessage", "GetResult", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc1");
//PortType
PortType port_type = sd.PortTypes ["IMetadataExchange"];
Assert.IsNotNull (port_type, "#exc2, PortType named IMetadataExchange not found.");
Assert.AreEqual (1, port_type.Operations.Count, "#exc3");
Operation op = port_type.Operations [0];
Assert.AreEqual ("Get", op.Name, "#exc4");
Assert.AreEqual (2, op.Messages.Count, "#exc5");
CheckOperationMessage (op.Messages [0], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_InputMessage",
typeof (OperationInput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");
CheckOperationMessage (op.Messages [1], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_OutputMessage",
typeof (OperationOutput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse");
CheckSpecialMessage (ms, "#exc6");
Assert.AreEqual (1, we.GeneratedWsdlDocuments.Count, "GeneratedWsdlDocuments.Count");
Assert.AreEqual (1, we.GeneratedXmlSchemas.Count, "GeneratedXmlSchemas.Count");
}
[Test]
public void ExportBar1Contract ()
{
WsdlExporter we = new WsdlExporter ();
ContractDescription cd = ContractDescription.GetContract (typeof (Bar1));
we.ExportContract (cd);
}
//Helper methods
//Checks the ComplexType emitted for CLR type Message
void CheckSpecialMessage (MetadataSet ms, string label)
{
//Check ComplexType MessageBody
XmlSchema xs = GetXmlSchema (ms, "http://schemas.microsoft.com/Message", label + " #csm0");
foreach (XmlSchemaObject o in xs.SchemaTypes.Values) {
XmlSchemaComplexType complex_type = o as XmlSchemaComplexType;
if (complex_type == null)
continue;
if (complex_type.Name != "MessageBody")
continue;
//MessageBody
Assert.IsNotNull (complex_type.Particle, label + " #cms1");
Assert.AreEqual (typeof (XmlSchemaSequence), complex_type.Particle.GetType (), label + " #cms2");
XmlSchemaSequence seq = (XmlSchemaSequence) complex_type.Particle;
Assert.AreEqual (1, seq.Items.Count, label + " #cms3");
Assert.AreEqual (typeof (XmlSchemaAny), seq.Items [0].GetType (), label + " #cms4");
XmlSchemaAny any = (XmlSchemaAny) seq.Items [0];
Assert.AreEqual ("##any", any.Namespace, label + " #cms5");
Assert.AreEqual (0, any.MinOccurs, label + " #cms6");
Assert.AreEqual ("unbounded", any.MaxOccursString, label + " #cms6");
}
}
//somebody fix this name!
void ExportContractExpectException (WsdlExporter we, ContractDescription cd, Type exception_type, string msg)
{
try {
we.ExportContract (cd);
} catch (Exception e) {
if (e.GetType () == exception_type)
return;
Assert.Fail (String.Format ("[{0}] Expected {1}, but got : {2}", msg, exception_type, e));
}
Assert.Fail (String.Format ("[{0}] Expected {1}", msg, exception_type));
}
WSServiceDescription GetServiceDescription (MetadataSet ms, string ns, string msg)
{
foreach (MetadataSection section in ms.MetadataSections) {
WSServiceDescription sd = section.Metadata as WSServiceDescription;
if (sd == null)
continue;
if (sd.TargetNamespace == ns) {
/*Assert.AreEqual ("http://schemas.xmlsoap.org/wsdl/", section.Dialect, msg + " Dialect");
Assert.AreEqual (id, section.Identifier, msg + "Identifier");
Assert.AreEqual (0, section.Attributes.Count, "#cw4");*/
return sd;
}
}
Assert.Fail (String.Format ("[{0}] ServiceDescription for ns : {1} not found.", msg, ns));
return null;
}
XmlSchema GetXmlSchema (MetadataSet ms, string ns, string msg)
{
foreach (MetadataSection section in ms.MetadataSections) {
XmlSchema xs = section.Metadata as XmlSchema;
if (xs == null)
continue;
if (xs.TargetNamespace == ns) {
/*Assert.AreEqual ("http://schemas.xmlsoap.org/wxsl/", section.Dialect, msg + " Dialect");
Assert.AreEqual (id, section.Identifier, msg + "Identifier");
Assert.AreEqual (0, section.Attributes.Count, "#cw4");*/
return xs;
}
}
Assert.Fail (String.Format ("[{0}] XmlSchema for tns : {1} not found.", msg, ns));
return null;
}
Service GetService (WSServiceDescription sd, string name, string label)
{
Service ret = sd.Services [name];
if (ret == null)
Assert.Fail (String.Format ("[{0}] Service named '{1}' not found.", label, name));
return ret;
}
WSBinding GetBinding (WSServiceDescription sd, string name, string label)
{
WSBinding ret = sd.Bindings [name];
if (ret == null)
Assert.Fail (String.Format ("[{0}] Binding named '{1}' not found.", label, name));
return ret;
}
OperationBinding GetOperationBinding (WSBinding b, string name, string label)
{
foreach (OperationBinding op in b.Operations)
if (op.Name == name)
return op;
Assert.Fail (String.Format ("[{0}] OperationBinding named '{1}' not found.", label, name));
return null;
}
void CheckBasicHttpBinding (WSServiceDescription wsd, string binding_name, XmlQualifiedName binding_type,
string operation_name, string action, bool has_input, bool has_output, string label)
{
WSBinding b = GetBinding (wsd, binding_name, label);
OperationBinding op = GetOperationBinding (b, operation_name, label + " CheckBasicHttpBinding");
Assert.AreEqual (binding_type, b.Type, label + " #cbh0");
if (has_input) {
InputBinding inb = op.Input;
Assert.IsNotNull (inb, label + " #cbh1");
Assert.AreEqual (1, inb.Extensions.Count, label + " #cbh2");
Assert.AreEqual (typeof (SoapBodyBinding), inb.Extensions [0].GetType (), label + " #cbh3");
SoapBodyBinding soap_binding = (SoapBodyBinding) inb.Extensions [0];
Assert.AreEqual (SoapBindingUse.Literal, soap_binding.Use, label + " #cbh4");
if (action != null) {
Assert.AreEqual (1, op.Extensions.Count, label + " #chb5");
Assert.AreEqual (typeof (SoapOperationBinding), op.Extensions [0].GetType (), label + " #cbh6");
SoapOperationBinding sopb = (SoapOperationBinding) op.Extensions [0];
Assert.AreEqual (action, sopb.SoapAction, label + " #cbh7");
}
}
if (has_output) {
OutputBinding outb = op.Output;
Assert.IsNotNull (outb, label + " #cbh10");
Assert.AreEqual (1, outb.Extensions.Count, label + " #cbh11");
Assert.AreEqual (typeof (SoapBodyBinding), outb.Extensions [0].GetType (), label + " #cbh12");
SoapBodyBinding soap_binding = (SoapBodyBinding) outb.Extensions [0];
Assert.AreEqual (SoapBindingUse.Literal, soap_binding.Use, label + " #cbh13");
}
Assert.AreEqual (1, b.Extensions.Count, label + " #cbh20");
Assert.AreEqual (typeof (SoapBinding), b.Extensions [0].GetType (), label + " #cbh21");
SoapBinding sb = (SoapBinding) b.Extensions [0];
Assert.AreEqual (SoapBinding.HttpTransport, sb.Transport, label + " #cbh22");
}
void CheckServicePort (Service svc, string port_name, XmlQualifiedName binding_name, string address, string label)
{
Port port = svc.Ports [port_name];
Assert.IsNotNull (port, label + " #csp0");
Assert.AreEqual (port.Binding, binding_name, label + " #csp1");
Assert.AreEqual (1, port.Extensions.Count, label + " #csp2");
Assert.AreEqual (typeof (SoapAddressBinding), port.Extensions [0].GetType (), label + " #csp3");
SoapAddressBinding sab = (SoapAddressBinding) port.Extensions [0];
Assert.AreEqual (address, sab.Location, label + " #csp3");
}
void CheckContract_IEchoService2 (MetadataSet ms, string label)
{
WSServiceDescription wsd = GetServiceDescription (ms, "http://tempuri.org/", label + "#a1");
Assert.AreEqual (3, wsd.Messages.Count, "#cw5");
Assert.IsNotNull (wsd.Messages [0]);
// WSMessage m = wsd.Messages [0];
CheckMessage (wsd, "ThisIsEchoService_Echo_InputMessage", "http://tempuri.org/:Echo");
CheckMessage (wsd, "ThisIsEchoService_Echo_OutputMessage", "http://tempuri.org/:EchoResponse");
CheckMessage (wsd, "ThisIsEchoService_DoubleIt_InputMessage", "http://tempuri.org/:DoubleIt");
//PortTypes
Assert.AreEqual (1, wsd.PortTypes.Count, "#cw6");
PortType port = wsd.PortTypes [0];
Assert.AreEqual ("ThisIsEchoService", port.Name, "#cw7");
//Operations
Assert.AreEqual (2, port.Operations.Count, "#cw8");
//Operations [0]
Operation op = port.Operations [0];
Assert.AreEqual ("Echo", op.Name, "#co1");
Assert.AreEqual (0, op.Extensions.Count, "#co2");
Assert.IsNull (op.ParameterOrder, "#co3");
Assert.AreEqual ("", op.ParameterOrderString, "#co4");
Assert.AreEqual (0, op.Faults.Count, "#co5");
//OperationMessages
Assert.AreEqual (2, op.Messages.Count, "#co6");
Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co7");
CheckOperationMessage (op.Messages [0], "http://tempuri.org/:ThisIsEchoService_Echo_InputMessage",
typeof (OperationInput), "http://tempuri.org/ThisIsEchoService/Echo");
CheckOperationMessage (op.Messages [1], "http://tempuri.org/:ThisIsEchoService_Echo_OutputMessage",
typeof (OperationOutput), "http://tempuri.org/ThisIsEchoService/EchoResponse");
op = port.Operations [1];
Assert.AreEqual ("DoubleIt", op.Name, "#co8");
Assert.AreEqual (0, op.Extensions.Count, "#co9");
Assert.IsNull (op.ParameterOrder, "#co10");
Assert.AreEqual ("", op.ParameterOrderString, "#co11");
Assert.AreEqual (0, op.Faults.Count, "#co12");
//OperationMessages
Assert.AreEqual (1, op.Messages.Count, "#co13");
Assert.AreEqual (OperationFlow.OneWay, op.Messages.Flow, "#co14");
CheckOperationMessage (op.Messages [0], "http://tempuri.org/:ThisIsEchoService_DoubleIt_InputMessage",
typeof (OperationInput), "http://tempuri.org/ThisIsEchoService/DoubleIt");
/* FIXME: Assert.AreEqual (1, wsd.Types.Schemas.Count, "#co20");
XmlSchema xs = wsd.Types.Schemas [0];
Assert.AreEqual (4, xs.Includes.Count);
//FIXME: Check the imports.. */
}
void CheckContract_IEchoService (MetadataSet ms, string label)
{
WSServiceDescription wsd = GetServiceDescription (ms, "http://myns/echo", label + "#a0");
Assert.AreEqual (4, wsd.Messages.Count, "#cw5");
Assert.IsNotNull (wsd.Messages [0]);
//WSMessage m = wsd.Messages [0];
CheckMessage (wsd, "IEchoService_Echo_InputMessage", "http://myns/echo:Echo");
CheckMessage (wsd, "IEchoService_Echo_OutputMessage", "http://myns/echo:EchoResponse");
CheckMessage (wsd, "IEchoService_DoubleIt_InputMessage", "http://myns/echo:DoubleIt");
CheckMessage (wsd, "IEchoService_DoubleIt_OutputMessage", "http://myns/echo:DoubleItResponse");
//PortTypes
Assert.AreEqual (1, wsd.PortTypes.Count, "#cw6");
PortType port = wsd.PortTypes [0];
Assert.AreEqual ("IEchoService", port.Name, "#cw7");
//Operations
Assert.AreEqual (2, port.Operations.Count, "#cw8");
//Operations [0]
Operation op = port.Operations [0];
Assert.AreEqual ("Echo", op.Name, "#co1");
Assert.AreEqual (0, op.Extensions.Count, "#co2");
Assert.IsNull (op.ParameterOrder, "#co3");
Assert.AreEqual ("", op.ParameterOrderString, "#co4");
Assert.AreEqual (0, op.Faults.Count, "#co5");
//OperationMessages
Assert.AreEqual (2, op.Messages.Count, "#co6");
Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co7");
CheckOperationMessage (op.Messages [0], "http://myns/echo:IEchoService_Echo_InputMessage", typeof (OperationInput), "http://myns/echo/IEchoService/Echo");
CheckOperationMessage (op.Messages [1], "http://myns/echo:IEchoService_Echo_OutputMessage", typeof (OperationOutput), "http://myns/echo/IEchoService/EchoResponse");
op = port.Operations [1];
Assert.AreEqual ("DoubleIt", op.Name, "#co8");
Assert.AreEqual (0, op.Extensions.Count, "#co9");
Assert.IsNull (op.ParameterOrder, "#co10");
Assert.AreEqual ("", op.ParameterOrderString, "#co11");
Assert.AreEqual (0, op.Faults.Count, "#co12");
//OperationMessages
Assert.AreEqual (2, op.Messages.Count, "#co13");
Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co14");
CheckOperationMessage (op.Messages [0], "http://myns/echo:IEchoService_DoubleIt_InputMessage", typeof (OperationInput), "http://myns/echo/IEchoService/DoubleIt");
CheckOperationMessage (op.Messages [1], "http://myns/echo:IEchoService_DoubleIt_OutputMessage", typeof (OperationOutput), "http://myns/echo/IEchoService/DoubleItResponse");
/* FIXME: Assert.AreEqual (1, wsd.Types.Schemas.Count, "#co20");
XmlSchema xs = wsd.Types.Schemas [0];
Assert.AreEqual (4, xs.Includes.Count);
//FIXME: Check the imports.. */
}
void CheckOperationMessage (OperationMessage opmsg, string msg, Type type, string action)
{
Assert.AreEqual (type, opmsg.GetType (), "#com1");
Assert.AreEqual (msg, opmsg.Message.ToString (), "#com2");
Assert.AreEqual (0, opmsg.Extensions.Count, "#com3");
Assert.AreEqual (1, opmsg.ExtensibleAttributes.Length, "#com4");
Assert.IsNull (opmsg.Name, "#com5");
XmlAttribute attr = opmsg.ExtensibleAttributes [0];
Assert.AreEqual ("Action", attr.LocalName, "#ca1");
Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", attr.NamespaceURI, "#ca2");
Assert.AreEqual (action, attr.Value, "#ca3");
}
void CheckMessage (WSServiceDescription sd, string msg_name, string part_type)
{
CheckMessage (sd, msg_name, "parameters", part_type, false, "");
}
void CheckMessage (WSServiceDescription sd, string msg_name, string part_name, string part_type, bool is_type, string label)
{
WSMessage m = sd.Messages [msg_name];
Assert.IsNotNull (m, label + " : Message named " + msg_name + " not found.");
Assert.AreEqual (msg_name, m.Name, label + " #cm1");
Assert.AreEqual (0, m.Extensions.Count, label + " #cm2");
Assert.IsNull (m.ExtensibleAttributes, label + " #cm3a");
Assert.AreEqual (1, m.Parts.Count, label + " #cm3");
Assert.AreEqual (part_name, m.Parts [0].Name, label + " #cm9");
if (is_type) {
Assert.AreEqual ("", m.Parts [0].Element.ToString (), label + " #cm4");
Assert.AreEqual (part_type, m.Parts [0].Type.ToString (), label + " #cm4a");
} else {
Assert.AreEqual ("", m.Parts [0].Type.ToString (), label + " #cm5");
Assert.AreEqual (part_type, m.Parts [0].Element.ToString (), label + " #cm5a");
}
Assert.IsNull (m.Parts [0].ExtensibleAttributes, label + " #cm6");
Assert.AreEqual (0, m.Parts [0].Extensions.Count, label + " #cm7");
}
void WriteTo (WsdlExporter we, string name)
{
using (XmlTextWriter xw = new XmlTextWriter (name, Encoding.UTF8)) {
xw.Formatting = Formatting.Indented;
we.GetGeneratedMetadata ().WriteTo (xw);
}
}
[Test]
public void ExportEndpointTest5 () {
WsdlExporter we = new WsdlExporter ();
ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
se.Binding = new BasicHttpBinding ();
se.Address = new EndpointAddress ("http://localhost:8080");
we.ExportEndpoint (se);
MetadataSet ms = we.GetGeneratedMetadata ();
Assert.AreEqual (6, ms.MetadataSections.Count);
WSServiceDescription wsd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest5#1");
SoapBinding soapBinding = (SoapBinding) wsd.Bindings [0].Extensions [0];
Assert.AreEqual (SoapBindingStyle.Document, soapBinding.Style, "soapBinding.Style");
Assert.AreEqual (SoapBinding.HttpTransport, soapBinding.Transport, "soapBinding.Transport");
}
}
[DataContract]
public class dc
{
[DataMember]
string foo;
/* [DataMember]
dc me;
[DataMember]
some_enum en;
[DataMember]
NotReferenced nr;*/
[DataMember]
public FooNS.bar bb;
}
[ServiceContract (Namespace = "http://myns/echo")]
public interface IEchoService
{
[OperationContract]
string Echo (string msg, int num, dc d);
[OperationContract]
void DoubleIt (int it, string prefix);
/*[OperationContract]
void foo ();*/
}
[ServiceContract (Name = "ThisIsEchoService")]
public interface IEchoService2
{
[OperationContract]
string Echo (string msg, int num, dc d);
[OperationContract (IsOneWay = true)]
void DoubleIt (int it, string prefix);
/*[OperationContract]
void foo ();*/
}
[ServiceContract (Name = "AnotherService")]
public interface IEchoService3
{
[OperationContract]
string Echo (string msg, int num, dc d);
[OperationContract (IsOneWay = true)]
void DoubleIt (int it, string prefix);
/*[OperationContract]
void foo ();*/
}
[ServiceContract]
public class Bar1
{
[OperationContract]
public void Foo (SMMessage msg, string s)
{
}
}
[ServiceContract]
public interface IFoo1
{
//Same DataContract used in different operations
[OperationContract]
void Op1 (dc d);
[OperationContract]
void Op2 (dc d);
}
//Used to check whether both IFoo1 & IFoo1a
//can be exported
//Operations are not Service scoped
[ServiceContract]
public interface IFoo1a
{
[OperationContract]
void Op1 (string s);
}
[ServiceContract]
public interface IFoo2
{
// FIXME: it does not pass yet
[OperationContract]
OregoMessage Nanoda (OregoMessage msg);
// FIXME: it does not pass yet
[OperationContract]
Mona NewMona (Mona source);
}
[MessageContract]
public class OregoMessage
{
[MessageBodyMember]
public string Neutral;
[MessageBodyMember]
public Assembly Huh;
[MessageBodyMember] // it should be ignored ...
public string Setter { set { } }
public string NonMember;
}
[DataContract]
public class Mona
{
[DataMember]
public string OmaeMona;
[DataMember]
public string OreMona;
}
}
namespace FooNS
{
[DataContract]
public class bar
{
[DataMember]
public string foo;
}
}
#endif
|