<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面把它拋出這樣從調用Objective C的一個asp.net web服務以JSON格式參數
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
我的目標C代碼的例外是:發生在NSJSONSerialization線
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");
例外。 所以這是我的問題的延續Web service method not hit when called via Objective C我改變了我的代碼,所以我發佈了一個新問題。這是我寫在asp端uritemplate的正確方法嗎?是我在iOS端調用的正確方式嗎?如果您需要更多信息,請告訴我。謝謝..
是'jUrlString'是否正確? – mkral
請NSLog的網址,並檢查它是否正確 –
@MidhunMP我改變了我的代碼上面。我添加了NSLog,並在contactoptions後添加了'/',它的輸出如下https://xyz-dev.com/GetEmployees.svc/JSON/contactoptions /?strCustomerID = 123。我將它粘貼到我的瀏覽器中,並輸出10條記錄。 – RookieAppler