询问者
WebService可以完全不需处理的返回一个dataset,却不能返回一个字符串数组?

问题
-
服务端:
[WebMethod]
public string[] mthRSAKeyGet()
{
string strRSAPrivateKey="", strRSAPublicKey="";
string[] astrRSAKey = new string[] {strRSAPublicKey, strRSAPrivateKey };
return astrRSAKey;
}
在客户端用以下代码调用出错:
BAService.User.LoginSoapClient seeLogin = new BAService.User.LoginSoapClient("LoginSoap", ProjectClassLibrary.CommonClass.Source + "User/Login.asmx");
string[] astrRSAKey = seeLogin.mthRSAKeyGet();
出错信息:无法将类型“BA.BAService.User.ArrayOfString”隐式转换为“string[]”
我知道可以用seeLogin.mthRSAKeyGet().ToArray()即可解决问题,我只是很好奇为什么我明明标定的返回值是字符串数组,返回结果变成ArrayOfString(List<string>)了?
而datatable和byte[]等却可以不需任何转换直接返回,这是为何?或者说Web Services这样设计基于何种考虑?另外除了ToArray方式是否还有其它方式让WebMethod直接返回字符串数组?
以上是使用vs2010添加默认的服务引用时才会导致,如果在添加服务引用时点击高级选择web引用生成的代理返回的是string[],这是为何?为什么2.0的web引用可以直接返回string[],而3.5的服务引用只能返回List[string]?
- 已编辑 eakey2014 2014年1月20日 2:42 标题不明
全部回复
-
应该是你生成的LoginSoapClient 里的契约定义有问题
-
Hi,
According research, if you want to get the string[] in the client in one of two ways suggested in this post:
- a) by creating a WCF service instead of an ASMX service, and using Add Service Reference.
- b) by keeping the asmx service, and using Add Web Reference instead of Add Service Reference.
Best Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="HYPERLINK ">HERE</a> to participate the survey.