私の App_Code/IGetEmployees.vb ファイル
<ServiceContract()> _
Public Interface IGetEmployees
<OperationContract()> _
<WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="json/contactoptions")> _
Function GetAllContactsMethod(strCustomerID As String) As List(Of NContactNames)
End Interface
私の App_Code/GetEmployees.vb ファイル
<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
NContactNames は、3 つのプロパティを持つクラスです。そのため、ASP.NET Web サービスを使用して SQL サーバーから情報を取得し、JSON 形式で iPad に渡しています。パラメータの受け渡しに問題があります。ご覧のとおり、IGetEmployees.vb と GetEmployees.vb の 2 つのファイルがあります。メソッド GetAllContactsMethod を実装しています。何が起こっているかというと、GetEmployees.vb ファイル (Utilities.log) の 2 行で、ログに記録されません。関数はまったく呼び出されていません。
この関数を呼び出す私の目的のCコード
NSString *param = [NSString stringWithFormat:@"strCustomerID=%@",strCustomerID];
jUrlString = [NSString stringWithFormat:@"%@",@"http://xyz-dev.com/GetEmployees.svc/json/contactoptions"];
jurl = [NSURL URLWithString:jUrlString];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:jurl];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[param dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@" request string is %@",[[request URL] absoluteString]);
NSLog(@"Done");
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection)
{
jData = [NSMutableData data];
NSError *jError;
NSMutableDictionary *json =[NSJSONSerialization JSONObjectWithData:jData options:kNilOptions error:&jError];
NSLog(@"%@",json); //Gets Here and prints (null)
NSLog(@"Done"); //prints this as well.
}
else
{
NSLog(@"No");
}
このコードを投稿した時点で、「if」ステートメントは true であり、(null) が出力され、その後に「Done」が表示されます。絶対要求の出力は次のとおりです。要求文字列はhttp://xyz-dev.com/GetEmployees.svc/ json/contactoptions パラメータを受け入れるために json を書くのはこれが初めてです。Visual Studio 側で関数がまったく呼び出されないのはなぜですか。さらに情報が必要な場合は、お問い合わせください。ありがとうございます...