<ServiceContract()> _
Public Interface IGetEmployees
<OperationContract()> _
<WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Json,BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="json/contactoptions/?strCustomerID={strCustomerID}")> _
Function GetAllContactsMethod(strCustomerID As String) As List(Of NContactNames)
End Interface
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function GetAllContactsMethod(strCustomerID As String) As List(Of NContactNames) Implements IGetEmployees.GetAllContactsMethod
Utilities.log("Hit get all contacts at 56")
Dim intCustomerID As Integer = Convert.ToInt32(strCustomerID)
Dim lstContactNames As New List(Of NContactNames)
'I add some contacts to the list.
Utilities.log("returning the lst count of " & lstContactNames.Count)
Return lstContactNames
End Function
因此,当我编写上述代码并在浏览器中调用它时,像这样http://xyz-dev.com/GetEmployees.svc/json/contactoptions/?strCustomerID=123我得到 10 行作为 JSON 格式的结果。这正是我的意图。但是当我从目标 c 端调用时,它会抛出这样的异常
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
我的目标c代码是:
NSString *strCustomerID = [NSString stringWithFormat:@"%i",123];
jUrlString = [NSString stringWithFormat:@"%@?strCustomerID=%@",@"https://xyz-dev.com/GetEmployees.svc/json/contactoptions/",strCustomerID];
NSLog(@"the jurlstring is %@",jUrlString);
NSURL *jurl = [NSURL URLWithString:jUrlString];
NSError *jError;
NSData *jData = [NSData dataWithContentsOfURL:jurl];
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:jData options:kNilOptions error:&jError];
NSLog(@"%@",json);
NSLog(@"Done");
NSJSONSerialization 行发生异常。所以这是我的问题的延续,Web service method not hit when called via Objective C我稍微改变了我的代码,所以我发布了一个新问题。这是我在 asp 端编写 uritemplate 的正确方式吗?这是我在 iOS 端调用的正确方式吗?如果您需要更多信息,请告诉我。谢谢..