Post your current code and some details on your server setup and we can help you diagnose your problem.
@interface testingViewController : UIViewController
<UIActionSheetDelegate> {
IBOutlet UITextField *NameField;
IBOutlet UIButton *SUBMITButton;
NSMutableData *webData;
}
@property (retain, nonatomic) UITextField *NameField;
@property (retain, nonatomic) UIButton * SUBMITButton;
-(IBAction)textFieldDoneEditing: (id)sender;
-(IBAction)SUBMITPressed: (id)sender;
@property (retain, nonatomic) NSMutableData *webData;
@end
#import "testingViewController.h"
@implementation testingViewController
@synthesize NameField;
@synthesize SUBMITButton;
@synthesize webData;
-(IBAction)textFieldDoneEditing: (id)sender
{
[sender resignFirstResponder];
}
- (IBAction)SUBMITPressed: (id)sender {
if (![sender isKindOfClass:[UIButton class]])
return;}//really do not know what code should be
-(void)Upload
{
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\"xmls:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<Upload xmlns=\"http://tempuri.org/\">\n"
"<name>%@</name>\n"
"</Upload>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",NameField.text
];
NSURL *url = [NSURL URLWithString:@"http://10.11.10.91/vesupload/Service.asmx?wsdl"];
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://10.11.10.91/vesupload/UploadImage" 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");
}
}
SOAPAction:"http://tempuri.org/Upload"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmls:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmls:soap="http://schemas.xmlsoap.org/soap/envelope/">\n"
"<soap:Body>\n"
"<Upload xmlns=\"http://tempuri.org/\">\n"
"<name>string</name>\n"
"</Upload>\n"
"</soap:Body>\n"
"</soap:Envelop>\n"
You don't appear to be calling [self Upload] from your SUBMITPressed: method.
- (IBAction)SUBMITPressed: (id)sender {
[self Upload];
}
Or using code tags to make it easy to read on the forum![]()
If your code is supposed to upload when the submit button is tapped then your action method should look like
Code:- (IBAction)SUBMITPressed: (id)sender { [self Upload]; }
which will start your POST.
Otherwise, tell us what you want to happen and what does happen.
What do your NSURLConnection delegate methods look like?
No, that's just where you set the delegate, not the delegate methods themselves (like, for example in this case, connection:didReceiveResponse:). If that doesn't make sense, I suggest stepping away from the real coding and going and (re)learning the basics of Objective-C.NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
No, that's just where you set the delegate, not the delegate methods themselves (like, for example in this case, connection:didReceiveResponse:). If that doesn't make sense, I suggest stepping away from the real coding and going and (re)learning the basics of Objective-C.
#pragma mark NSURLConnection delegate methods
-(void)connection: (NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response
{
[webData setLength: 0];
NSLog(@"connection: didReceiveResponse:1");
}
-(void)connection: (NSURLConnection *)connection didReceiveData: (NSData *)data
{
[webData appendData:data];
NSLog(@"connection: didReceiveData:2");
}
-(void)connectionDidFinishLoading: (NSURLConnection *)connection
{
NSLog(@"3 DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(theXML);
[theXML release];
}
The code seems to be right, but only insomuch as it encounters no problems, which obviously you are. Have you coded a connection:didFailWithError:? You say it's not working. Please elaborate? Are you getting run-time errors? How much of the NSLogs you've included are being executed?I got the code like this,but still not working.Is the code right?
The code seems to be right, but only insomuch as it encounters no problems, which obviously you are. Have you coded a connection:didFailWithError:? You say it's not working. Please elaborate? Are you getting run-time errors? How much of the NSLogs you've included are being executed?
-(void)connection: (NSURLConnection *)connection didFailWithError: (NSError *)error
{
NSLog(@"ERROR with theConnection"):
[connection release];
[webData release];
}
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).I do not have any errors or warnings after I click 'Bulid and Run'. The problem is I got nothing on my webservice. I want to send a 'name.text' on my webservice, but I got nothing.
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).
I didn't get an answer to this question: How much of the NSLogs you've included are being executed?
Also, the issue may exist on the server side. Is it receiving the SOAP request and responding appropriately?
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).
I didn't get an answer to this question: How much of the NSLogs you've included are being executed?
Also, the issue may exist on the server side. Is it receiving the SOAP request and responding appropriately?
Is that the line where you set the breakpoint? If so, then that's where it's supposed to stop.also I use the breakpoints, it stop at
NSURL *url = [NSURL URLWithString"http://10.11.10.91/vesupload/Service.asmx?wsdl"];
Ah. That's what I suspected but didn't realize the private space included everything after the 10. So used to seeing 10.0.1.x. Thanks for clarifying that.10.x.x.x is ipv4's private address space. It is never routed onto the internet.