29,027
社区成员
发帖
与我相关
我的任务
分享
public class FileService {
public String upload(DataHandler handler, String fileName) {
//存文件的一系列操作
}
}
<element name="upload">
<complexType>
<sequence>
<element name="handler" type="apachesoap:DataHandler"/>
<element name="fileName" type="xsd:string"/>
</sequence>
</complexType>
</element>
NSString *soapMessage = [NSString stringWithFormat:
@"<?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/\">"
"<soap:Body>\n"
"<ns1:upload xmlns:ns1=\"http://10.188.96.27:8080/AudioService/services/FileService?wsdl\">"
"<arg0>%@</arg0>"
"<arg1>%@</arg1>"
"</ns1:upload>"
"</soap:Body>\n"
"</soap:Envelope>",@"aaaadd", @"aa.txt"];
NSLog(@"调用webserivce的字符串是:%@",soapMessage);
//请求发送到的路径
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
NSURL *url = [NSURL URLWithString:@"http://10.188.96.27:8080/AudioService/services/FileService?wsdl"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
//以下对请求信息添加属性前四句是必有的,
[urlRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue: @"http://10.188.96.27:8080/AudioService/services/FileService?wsdl" forHTTPHeaderField:@"SOAPAction"];
[urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
//请求
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
theConnection = nil;