XML Question

Discussion in 'Mac Programming' started by mickwaffle, Jun 14, 2010.

  1. mickwaffle macrumors newbie

    Joined:
    Jun 14, 2010
    #1
    hi, im looking for a bit of help with XML and SOAP.
    I am currently sending data to a web server using. I am using WSMethodInvocation. to sete the parameters, I use WSMethodInvocationSetParameters. However, I am now wondering, how can I add atrributes to my parameters. A the moment I can only do this sort of thing: <parameter > Some text</parameter>
    However, I am looking to be able to do something like this:
    <parameter value="sometext" > Some text</parameter>

    thanks
     
  2. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #2
    Have you tried using WSMethodInvocationSetProperty?
     
  3. mickwaffle thread starter macrumors newbie

    Joined:
    Jun 14, 2010
    #3
    im not sure how i would use that... i think thats just used for setting properties of the actual WSMethodInvocation as opposed to the actual parameters.
     
  4. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #4
    Maybe you could explain what you are trying to do a little bit more clearly. I don't understand why you would have to touch the actual XML message being sent.
     
  5. mickwaffle thread starter macrumors newbie

    Joined:
    Jun 14, 2010
    #5
    this is my code:

    Code:
    // SOAP call settings
    	NSURL *url = [NSURL URLWithString:@"http://localhost/Service.asmx"];
    	NSString *method = @"myMethod";
    	NSString *namespace = @"http://localhost/namespace";
    	
    	NSDictionary *params = [NSDictionary dictionaryWithObject:@"TEXT VALUE"forKey:@"myParameter"];
    	NSArray *paramOrder = [NSArray arrayWithObject:@"myParameter"];
    	
    	// SOAP call http headers -- some SOAP server impls require even empty SOAPAction headers
    	NSDictionary *reqHeaders = [NSDictionary dictionaryWithObject:@"" forKey:@"SOAPAction"]; 
    	
    	WSMethodInvocationRef soapReq = createSOAPCall(url, method, namespace, params, paramOrder, reqHeaders, soapHeaders);
    
    The function:
    
    WSMethodInvocationRef createSOAPCall(NSURL *url,
                                         NSString *method,
                                         NSString *namespace,
                                         NSDictionary *params,
                                         NSArray *paramOrder,
                                         NSDictionary *reqHeaders)
    {
        WSMethodInvocationRef soapReq = WSMethodInvocationCreate((CFURLRef)url,
                                                                  (CFStringRef)method,
                                                                  kWSSOAP2001Protocol);
    	
        
    	
        WSMethodInvocationSetParameters(soapReq, (CFDictionaryRef)params, (CFArrayRef)paramOrder);
    	
    	
    	
        // set method namespace
        WSMethodInvocationSetProperty(soapReq, kWSSOAPMethodNamespaceURI, (CFStringRef)namespace);
    	
        // Add HTTP headers (with SOAPAction header) -- some SOAP impls require even empty SOAPAction headers
        WSMethodInvocationSetProperty(soapReq, kWSHTTPExtraHeaders, (CFDictionaryRef)reqHeaders);
    	
        // for good measure, make the call follow redirects.
        WSMethodInvocationSetProperty(soapReq,    kWSHTTPFollowsRedirects, kCFBooleanTrue);
    	
        // set debug props
    	
    	
        WSMethodInvocationSetProperty(soapReq, kWSDebugIncomingBody,     kCFBooleanTrue);
        WSMethodInvocationSetProperty(soapReq, kWSDebugIncomingHeaders, kCFBooleanTrue);
        WSMethodInvocationSetProperty(soapReq, kWSDebugOutgoingBody,     kCFBooleanTrue);
        WSMethodInvocationSetProperty(soapReq, kWSDebugOutgoingHeaders, kCFBooleanTrue);
    	
        return soapReq;
    }
    
    I am trying to use apples Web Services to send soap requests to my server. However, instead of having just <myParameter>TEST VALUE</myParameter> in the method body... i need to have <myParameter value="another_value">TEST VALUE</myParameter>
     
  6. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #6
    I mis-typed. I meant to suggest you use: WSMethodInvocationSetParameters

    But it looks like you are already using it. The XML-RPC format does not support what you are trying to do. Generally it is in the format:
    ...
    <params>
    <param>
    <value> <TYPE>value</TYPE> </value>
    <param>
    ...
    </params>

    If the web-service you are consuming is not in strict compliance with XML-RPC you may need to use a third party tool.
     
  7. mickwaffle thread starter macrumors newbie

    Joined:
    Jun 14, 2010
    #7
    ok, thanks a lot for your help :)
    let's say i was to go ahead, and make my xml soap request myself, just as a regular string, what function would i then use to send it off to my webservice?
    thanks again
     
  8. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #8
    That's easier in many cases. Just use amy http transport protocol. It's guaranteed to work over http.
     

Share This Page