下面是我的SOAP请求,它不起作用,我也粘贴了响应。不知何故,代替响应xml下面的代码只返回WSDL xml。我在SOAPUI中尝试了相同的SOAP请求,并在那里得到了适当的响应。
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];
预期输出是这样的,我从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>
但是我得到的结果是巨大的WSDL本身,我将在这里粘贴它的一部分。
<?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>
我的代码看起来很好。而且我很长一段时间都在努力为什么我没有得到响应而不是WSDL但是没有运气。请建议。任何建议都是最受欢迎的。谢谢!
答案 0 :(得分:1)
我解决了这个问题。问题出在请求中。请求没有正确发送,这就是为什么我没有收到任何回复。我改变了,使用AFNetworking并且它工作了!!