Search code examples
iosobjective-cweb-servicessoapwsdl

Objective C - SOAP request return WSDL in response instead of proper response


Below is my SOAP request and its not working , I have pasted the response as well. Somehow instead of response xml below code returns the WSDL xml only. I tried same SOAP request in SOAPUI and i get proper response there.

NSString *soapMessage =
    @"<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"> \
    <x:Header/> \
    <x:Body> \
    <tem:GetInfo> \
    <tem:MID>150XXXXXX693</tem:MID> \
    </tem:GetInfo> \
    </x:Body> \
    </x:Envelope>";
    NSURL *url = [NSURL URLWithString:@"http://myservice/Service.asmx?WSDL"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest addValue:@"http://tempuri.org/GetInfo" forHTTPHeaderField:@"SOAPAction"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLSession *soapSession = [NSURLSession sessionWithConfiguration:   [NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
    NSURLSessionDataTask *dataTask = [soapSession dataTaskWithURL: url];
    self.responseData = [[NSMutableData alloc]init];
    [dataTask resume];

Expected Output is something like this which i got from SOAPUI -

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetInfoResponse xmlns="http://tempuri.org/">
         <GetInfoResult><![CDATA[<RESPONSE><REQUEST_STATUS><CODE>000</CODE><DESCRIPTION>Operation Completed Successfully</DESCRIPTION><SEVERITY>I</SEVERITY><ORIGIN>W</ORIGIN><SERIAL_NUMBER></SERIAL_NUMBER></REQUEST_STATUS><OUTPUT><Code>XXX</Code><Number>000</Number><Name>XXX</Name><AddressLine1>139 XXX E.</AddressLine1><AddressLine2>XXX 103</AddressLine2></OUTPUT></RESPONSE>]]></GetInfoResult>
      </GetInfoResponse>
   </soap:Body>
</soap:Envelope> 

But Result I get is the huge WSDL itself, i will just paste some part of it here.

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:element name="GetCurrentDate">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="MachineID" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
<s:element name="GetInfo">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="MID" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetInfoResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetInfoResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
 </s:schema>
  </wsdl:types>
  <wsdl:message name="GetCurrentDateSoapIn">
    <wsdl:part name="parameters" element="tns:GetTradeDate" />
  </wsdl:message>
 <wsdl:portType name="Service">
<wsdl:operation name="GetInfo">
      <wsdl:input message="tns:GetInfoSoapIn" />
      <wsdl:output message="tns:GetInfoSoapOut" />
    </wsdl:operation>
  </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

My code looks fine to me. And I am trying from long time that why i am not getting response instead of of WSDL but no luck yet. Please suggest. Any suggestions are most welcome. Thanks!


Solution

  • I got this resolved. The issue was in the request. Request was not properly sent and that is why i was not getting any response. I changed that, used AFNetworking and it worked!!