其余不变,有什么事情发生那?执行之,第一个界面不变,但是有invoke按钮的那个页面就不同了,多了一个表格,parameter那一列多了个strInput:,value那列多了一个text box。喔,原来是在text box里面输入strInput的值。随便打什么,比方说"Nfs is the best",按invoke按钮,返回如下信息:
<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://tempuri.org/">Nfs is the best Hello World</string>
会用了吗?
3.在变化一些,输入参数变为数组
public string HelloWorld(string[] str) { return str[0]+"Hello World"; }
执行之,第一个页面好像没什么问题,但是一点hello world这个链接,就好像出错了!
Test Test forms are only available for methods with non-array primitive types as parameters. SOAP The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values. .............
public class Foo { public Foo(int x) { str=new string[x]; } public string[] str; } public string HelloWorld(Foo FooTest) { for(int i=0;i<FooTest.str.Length;i++) FooTest.str[i]+=" Hello World"+i.ToString(); //do something return "Hello World"; }
编译,完了,第一个页面就说:
Server Error in ’/WebService4’ Application. WebService4.Service1+Foo cannot be serialized because it does not have a default public constructor. Description: An unhandled exception occurred during the execution of the current web request.Please review the stack trace for more information about the error and where it originated in the code. Exception Details:System.Exception: WebService4.Service1+a cannot be serialized because it does not have a default public constructor. Source Error:一大堆Error
Test No test form is available as this service or method does not support the HTTP GET protocol. SOAP The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.
没事的,象3中情况一样,调用是没有问题的,放心!
5.好像都将完了吧?没有!诸位有没有考虑到在人家的程序中调用我的时候,怎样定的输入参数的类型?该类型使我自己定义的啊!如上变量Foo。好,我们到刚才生成的Windows Application里面看看那。在Solution Explore中的localhost,右键选择Update Web Referece。(我们改过,他可不知道,呵呵)把原来的语句改成: