views:

47

answers:

1

Hi friends,

I am working with coneect to SOAP webservice from iphone. I cant connect with the web service. Here i had included my code. Please help me to solve the problem.

        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/\"&gt; \n"
        "xmlns:mob=\"http://XXX.edu\"&gt;\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://tempuri.org/"&gt;
        <wsdl:import namespace="http://YYY/" location="https://XXX/UserService.svc/basic?wsdl=wsdl1"/&gt;
        <wsdl:types/>
        <wsdl:service name="UserService">
        <wsdl:port name="ZZZ" binding="i0:ZZZ">
        <soap:address location="https://XXX/UserService.svc"/&gt;
        </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.
A: 

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.

zoomer.hammerball