How to connect with the SOAP web service?
I am working with connect to SOAP webservice from iPhone. I can't connect with the web service. Here I had included my code:
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"xmlns:mob=\"http://XXX.edu\">\n"
"<SOAP-ENV:Body> \n"
"<mob:Login>\n"
"<mob:username>User Name</mob:username>\n"
"<mob:password>Password</mob:password>\n"
"</mob:Login>\n"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>"];
NSURL *url = [NSURL URLWithString:@"https://YYY.edu/UserService.svc"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[request addValue: @"Login" forHTTPHeaderField:@"SOAPAction"];
[request addValue: @"text/xml; charset=\"utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"https://YYY/UserService" forHTTPHeaderField:@"Host"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
WSDL URL : https://XXX/UserService.svc?wsdl
End point : https://XXX/UserService.svc
**WSDL XML format**
<wsdl:definitions name="UserService" targetNamespace="http://temp开发者_如何学Curi.org/">
<wsdl:import namespace="http://YYY/" location="https://XXX/UserService.svc/basic?wsdl=wsdl1"/>
<wsdl:types/>
<wsdl:service name="UserService">
<wsdl:port name="ZZZ" binding="i0:ZZZ">
<soap:address location="https://XXX/UserService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This is the XMl format and request input i had used. I cant connect with the web service. I got the error message (response) is either empty or "<h1>Bad Request (Invalid Hostname)</h1>".
where i am getting lack. Please any one help me.
Thanks in advance.
Try to change the host, in webservices you can check the Host header to match with the host where you are publishing the webservice. Probably setting the header "Host: " parameter to a right value could fix the problem. Put only the host:port in that header parameter.
精彩评论