Web サービス ( ) を作成し、その中に文字列を返すSampleService.asmx
メソッド ( ) を配置します。GetAllUserInfo2
私はそれをテストしVisual Studio
、適切に動作します。
以下のメッセージを使用して消費し、ログファイルを確認しますが、エラーが発生します
//Message
NSString *soapMessage=@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<GetCategory xmlns=\"http://jahanmir.ir/\" />\n"
"</soap:Body>\n"
"</soap:Envelope>";
NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"http://www.jahanmir.ir/SampleService.asmx"]];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//[theRequest addValue:@"http://jahanmir.ir/GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:@"http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"];
NSString *msgLength=[NSString stringWithFormat:@"%i",[soapMessage length]];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(con)
webData=[[NSMutableData data] retain];//webData is `NSMutableData`
//Log
2012-10-22 17:39:50.533 WebServices[522:f803] data: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>