6
我想從iOS應用程序調用.NET ASMX服務。我創建了這樣的SOAP消息:從iOS應用程序發送參數到SOAP ASMX服務
-(IBAction)submitButtonClicked:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/NotificationService.asmx"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
[request addRequestHeader:@"SOAPAction" value:@"http://tempuri.org/HelloWorld"];
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<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>"
"<Greet xmlns=\"http://tempuri.org/\">"
"<deviceToken>some device token</deviceToken>"
"<userName>azamsharp</userName>"
"</Greet>"
"</soap:Body>"
"</soap:Envelope>"];
NSString *messageLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[request addRequestHeader:@"Content-Length" value:messageLength];
[request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[request setDelegate:self];
[request startAsynchronous];
}
上面的代碼工作正常,但您可以看到我必須手動創建SOAP消息。有沒有什麼方法可以傳入參數,方法名稱和soap body/message是自動創建的。 StackOverFlow上有一個例子用於相同的場景,但我無法找到它。
你有這個運氣嗎? – zaitsman
@zaitsman,看看我剛剛發佈的答案...都有點過時,但這可能會幫助你? – Purpletoucan