Web service test tool (including source code)

Source: Internet
Author: User

Web Service is familiar to everyone. When interactions between multiple systems are very frequent, Web services must always be tested during development to ensure that web services can run normally. The common method is to enter the Web service address for testing. However, WebService is often deployed on other machines and cannot be directly tested. You can only write the testCodeThe test is very complicated. Here, we can dynamically call the Web Service for testing.

Dynamic call of web service methods

Public   Static   Object Invokewebservice ( String URL, String Methodname, Object [] ARGs)
{
Try
{
String @ Namespace =   " WebService. dynamicwebcalling " ;
String [] Parts = URL. Split ( ' / ' );
String [] PPS = Parts [parts. Length -   1 ]. Split ( ' . ' );
String Classname = PPS [ 0 ];
System. net. WebClient WC =   New System. net. WebClient ();
System. Io. Stream stream = WC. openread (URL +   " ? WSDL " );
System. Web. Services. description. servicedescription SD = System. Web. Services. description. servicedescription. Read (Stream );
System. Web. Services. description. servicedescriptionimporter SDI =   New System. Web. Services. description. servicedescriptionimporter ();
SDI. addservicedescription (SD, "" , "" );
System. codedom. codenamespace CN =   New System. codedom. codenamespace (@ namespace );
System. codedom. codecompileunit CCU =   New System. codedom. codecompileunit ();
CCU. namespaces. Add (CN );
SDI. Import (CN, CCU );

Microsoft. CSHARP. csharpcodeprovider CSC =   New Microsoft. CSHARP. csharpcodeprovider ();
System. codedom. compiler. icodecompiler ICC = CSC. createcompiler ();

System. codedom. compiler. compilerparameters cplist =   New System. codedom. compiler. compilerparameters ();
Cplist. generateexecutable =   False ;
Cplist. generateinmemory =   True ;
Cplist. referencedassemblies. Add ( " System. dll " );
Cplist. referencedassemblies. Add ( " System. xml. dll " );
Cplist. referencedassemblies. Add ( " System. Web. Services. dll " );
Cplist. referencedassemblies. Add ( " System. Data. dll " );

System. codedom. compiler. compilerresults cr = ICC. compileassemblyfromdom (cplist, CCU );
If ( True   = Cr. errors. haserrors)
{
System. Text. stringbuilder sb =   New System. Text. stringbuilder ();
Foreach (System. codedom. compiler. compilererror CE In Cr. Errors)
{
SB. append (Ce. tostring ());
SB. append (system. environment. newline );
}
Throw   New Exception (sb. tostring ());
}
System. reflection. Assembly = Cr. compiledassembly;
Type T = Assembly. GetType (@ namespace +   " . "   + Classname, True , True );
Object OBJ = Activator. createinstance (t );
System. reflection. methodinfo Mi = T. getmethod (methodname );
Return Mi. Invoke (OBJ, argS );
}
Catch (Exception ex)
{
ThrowEx;
}
}

ProgramRun Interface

Source codeDownload
/Files/binbin1845/wstest.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.