2016-06-16 7 views
0

Wie soll ich diese Anfrage auf iOS in Objective C machen?Wie SOAP-Anfrage in Objective C zu buchen?

POST /WS/CustomerServices.asmx HTTP/1.1 
Host: mesereser.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <AddContactToGroup_BasicInfo xmlns="http://mesereser.com/"> 
     <oLogin> 
     <UserName>string</UserName> 
     <Password>string</Password> 
     </oLogin> 
     <iUserID>int</iUserID> 
     <sGroupName>string</sGroupName> 
     <oContact> 
     <FirstName>string</FirstName> 
     <LastName>string</LastName> 
     </oContact> 
    </AddContactToGroup_BasicInfo> 
    </soap12:Body> 
</soap12:Envelope> 

Antwort

0

Sie können diesen Code versuchen:

NSString *urn = @"urn:IServiceFactorySilverlight"; 
NSString *namespace = @""; 

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/\">\n" 
         "<soap:Body>\n" 
         "<%@ %@>\n" 
         "%@" 
         "</%@>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>\n" 
         ,method, namespace, params, method]; 


NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 
NSString *msgLength = [NSString stringWithFormat:@"%ld", (long)[soapMessage length]]; 
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: [NSString stringWithFormat:@"%@/%@",urn,method] forHTTPHeaderField:@"soapaction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
0

Hier ist der Code an den Server zu senden:

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/\">\n" 
        "<soap:Body>\n" 
        "<%@ %@>\n" 
        "%@" 
        "</%@>\n" 
        "</soap:Body>\n" 
        "</soap:Envelope>\n" 
        ,method, namespace, params, method];        ]; 
NSLog(@"soapMessage: \n%@",soapMessage); 

NSURL *url = [NSURL URLWithString:@"???.asmx"]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: @"http://tempuri.org/GetMessages" forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

if(theConnection) 
    webData = [[NSMutableData data] retain]; 
else 
    NSLog(@"theConnection is NULL");