要重新创建我所看到的问题,使用VS2010,创建一个空网站并添加一个带有代码隐藏的Web服务(asmx).
使用以下代码,可以成功调用两个web方法:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
[WebMethod]
public void Method1(int x) {
// i'm good
}
[WebMethod]
public string Method2(int x) {
return "it worked";
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我将方法2上的parm更改为可空类型它可以正常工作,但它会使方法1失败...
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
[WebMethod]
public void Method1(int x) {
// no changes made to this method, but it no longer works
}
[WebMethod]
public string Method2(int? x) {
return "it worked";
}
}
Run Code Online (Sandbox Code Playgroud)
如果在调用服务时缺少参数,则会出现错误:
System.IndexOutOfRangeException:索引超出了数组的范围.在System.Web.Services.Protocols.HttpServer上的System.Web.Services.Protocols.HttpServerType..ctor(Type …
我有一个ASP.NET Web服务.这个Web服务工作正常.但是,WSDL将一些参数列为可选(minoccurs = 0),将其他参数列为非可选参数.一些可选参数实际上不是可选的,其他标记为非可选参数实际上是可选的.我想解决这个问题,但我找不到这些信息的来源.
在我看来,所有原始类型(int,boolean等)都是非可选的,所有其他参数都标记为可选.但是,我找不到可以更改此位置的位置.我想指定原始值的默认值(如果它们在请求中缺失)并指定哪个非基本参数实际上是可选的.我在哪里这样做?