强制忽略一些url参数

时间:2015-01-28 06:10:45

标签: c# .net web-services parameters asmx

我正在制作一个iPhone应用程序,我正在使用.NET webservice。

我们假设下面是我的网址。

http://www.myweb.com/wser.asmx/listOfStudents?class=12

我在这里收到了以下字段的学生名单。

Name
Roll Number
Class

现在客户要求制作阿拉伯语版本。所以我们将查询更新到下面。

http://www.myweb.com/wser.asmx/listOfStudents?class=12&appLang=ar
                                                      ^^^^^^^^^^^^

为了测试我们更新另一台服务器上的webservice&检查,一切正常。

现在在App Store上传应用程序时,我注意到如果我更新实际的webservice当前应用程序将无法正常工作,因为应用程序商店中的当前应用程序中缺少appLang变量。

如果我不更新webservice&苹果进入测试阶段,应用程序将崩溃,因为它会抛出缺少参数appLang的错误。

所以我在想的是,

我将上传新的网络服务,但appLang将是阿拉伯语BY-DEFAULT。

如果我使用更新的webservice(在webservice中添加appLang而不是在url中)执行url http://www.myweb.com/wser.asmx/listOfStudents?class=12,那么它不会抛出parameter missing appLang的错误吗?

有没有办法制作默认参数?

1 个答案:

答案 0 :(得分:1)

虽然在这种情况下使用GET并不是很好(POST可能更合适),但你可以这样做:

//by specifying a messageName, you can do overloading with webmethods
[WebMethod (MessageName = "listOfStudentsDefault")]  
[ScriptMethod(UseHttpGet=true)]
public string listOfStudents(int class, string appLang)
{
    // code here...
}

[WebMethod (MessageName = "listOfStudents")]  
[ScriptMethod(UseHttpGet=true)]
public string listOfStudents(int class)
{
    return listOfStudents(class, "ar");
}