iOS 上的 SOAP 不工作
我对 SOAP 很陌生,所以不要介意我的愚蠢。 我有一个 SOAP Web 服务,位于 http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ
WSDL 如下
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:intf="HTTP://207.7.208.250" targetNamespace="HTTP://207.7.208.250">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:intf="HTTP://207.7.208.250" elementFormDefault="qualified" targetNamespace="HTTP://207.7.208.250">
<element name="ProductInquiryResponse">
<complexType>
<sequence>
<element name="EclipsePN" type="string"/>
<element name="Description" type="string"/>
<element name="AlternateDescription" type="string"/>
<element name="UPC" type="string"/>
<element name="Catalog" type="string"/>
<element name="PartNumber" type="string"/>
<element name="AvailQty" type="string"/>
<element name="AvailDate" type="string"/>
<element name="AvailUOM" type="string"/>
<element name="Price" type="string"/>
<element name="PriceUOM" type="string"/>
<element name="ImageURL" type="string"/>
<element name="SpecSheetURL" type="string"/>
<element name="ErrorDescription" type="string"/>
</sequence>
</complexType>
</element>
<element name="ProductInquiry">
<complexType>
<sequence>
<element name="Login" type="string"/>
<element name="Password" type="string"/>
<element name="EclipsePN" type="string"/>
<element name="UPC" type="string"/>
<element name="HomeBranch" type="string"/>
</sequence>
</complexType>
</element>
<element name="CALL_SSI_MOBILE_PROD_INQ">
<complexType>
<sequence>
<element ref="intf:ProductInquiry"/>
</sequence>
</complexType>
</element>
<element name="CALL_SSI_MOBILE_PROD_INQResponse">
<complexType>
<sequence>
<element ref="intf:ProductInquiryResponse"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQResponse">
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQRequest">
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQ"></wsdl:part>
</wsdl:message>
<wsdl:portType name="SSI_MOBILE_PROD_INQ">
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ">
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest" message="intf:CALL_SSI_MOBILE_PROD_INQRequest"></wsdl:input>
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse" message="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SSI_MOBILE_PROD_INQSOAPBinding" type="intf:SSI_MOBILE_PROD_INQ">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SSI_MOBILE_PROD_INQ">
<wsdl:port name="SSI_MOBILE_PROD_INQ" binding="intf:SSI_MOBILE_PROD_INQSOAPBinding">
<wsdlsoap:address location="HTTP://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这就是我正在做的事情来获取...... 我想发送 UPC 代码并检索生成的 xml,然后我将解析并检索数据。
NSMutableString *sRequest = [[NSMutableString alloc] init];
[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[sRequest appendString:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
[sRequest appendString:@"<soap:Body>"];
[sRequest appendString:@"<SSI_MOBILE_PROD_INQ xmlns=\"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ/\">"];
[sRequest appendString:@"<CALL_SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"<UPC>"];
[sRequest appendString:@"78285630648"];
[sRequest appendString:@"</UPC>"];
[sRequest appendString:@"</CALL_SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"</SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"</soap:Body>"];
[sRequest appendString:@"</soap:Envelope>"];
NSURL *weatherServiceURL = [NSURL URLWithString:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherServiceURL];
[request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ" forHTTPHeaderField:@"SOAPAction"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
myMutableData = [NSMutableData data];
NSLog(@"Conn is true");
}
[NSURLConnection connectionWithRequest:request delegate:self];
NSError *WSerror;
NSURLResponse *WSresponse;
NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request
returningResponse:&WSresponse error:&WSerror];
if(WSerror){
NSLog(@"%@", [WSerror localizedDescription]);
}
if (returnData) {
NSString *content = [NSString stringWithUTF8String:[myMutableData bytes]];
DebugLog(@"yeah %@", content);
}
我没有从内容字符串中得到任何输出。 我想我没有正确调用 SOAP 方法......? 你有什么想法?
I am very new to SOAP so dont mind my stupidity.
I have a SOAP web service located at http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ
WSDL is as follows
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:intf="HTTP://207.7.208.250" targetNamespace="HTTP://207.7.208.250">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:intf="HTTP://207.7.208.250" elementFormDefault="qualified" targetNamespace="HTTP://207.7.208.250">
<element name="ProductInquiryResponse">
<complexType>
<sequence>
<element name="EclipsePN" type="string"/>
<element name="Description" type="string"/>
<element name="AlternateDescription" type="string"/>
<element name="UPC" type="string"/>
<element name="Catalog" type="string"/>
<element name="PartNumber" type="string"/>
<element name="AvailQty" type="string"/>
<element name="AvailDate" type="string"/>
<element name="AvailUOM" type="string"/>
<element name="Price" type="string"/>
<element name="PriceUOM" type="string"/>
<element name="ImageURL" type="string"/>
<element name="SpecSheetURL" type="string"/>
<element name="ErrorDescription" type="string"/>
</sequence>
</complexType>
</element>
<element name="ProductInquiry">
<complexType>
<sequence>
<element name="Login" type="string"/>
<element name="Password" type="string"/>
<element name="EclipsePN" type="string"/>
<element name="UPC" type="string"/>
<element name="HomeBranch" type="string"/>
</sequence>
</complexType>
</element>
<element name="CALL_SSI_MOBILE_PROD_INQ">
<complexType>
<sequence>
<element ref="intf:ProductInquiry"/>
</sequence>
</complexType>
</element>
<element name="CALL_SSI_MOBILE_PROD_INQResponse">
<complexType>
<sequence>
<element ref="intf:ProductInquiryResponse"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQResponse">
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQRequest">
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQ"></wsdl:part>
</wsdl:message>
<wsdl:portType name="SSI_MOBILE_PROD_INQ">
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ">
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest" message="intf:CALL_SSI_MOBILE_PROD_INQRequest"></wsdl:input>
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse" message="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SSI_MOBILE_PROD_INQSOAPBinding" type="intf:SSI_MOBILE_PROD_INQ">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SSI_MOBILE_PROD_INQ">
<wsdl:port name="SSI_MOBILE_PROD_INQ" binding="intf:SSI_MOBILE_PROD_INQSOAPBinding">
<wsdlsoap:address location="HTTP://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This is what I am doing to fetch...
I want to send in UPC code and retrive the resulting xml which I will then parse and retrieve data.
NSMutableString *sRequest = [[NSMutableString alloc] init];
[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[sRequest appendString:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
[sRequest appendString:@"<soap:Body>"];
[sRequest appendString:@"<SSI_MOBILE_PROD_INQ xmlns=\"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ/\">"];
[sRequest appendString:@"<CALL_SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"<UPC>"];
[sRequest appendString:@"78285630648"];
[sRequest appendString:@"</UPC>"];
[sRequest appendString:@"</CALL_SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"</SSI_MOBILE_PROD_INQ>"];
[sRequest appendString:@"</soap:Body>"];
[sRequest appendString:@"</soap:Envelope>"];
NSURL *weatherServiceURL = [NSURL URLWithString:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherServiceURL];
[request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ" forHTTPHeaderField:@"SOAPAction"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
myMutableData = [NSMutableData data];
NSLog(@"Conn is true");
}
[NSURLConnection connectionWithRequest:request delegate:self];
NSError *WSerror;
NSURLResponse *WSresponse;
NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request
returningResponse:&WSresponse error:&WSerror];
if(WSerror){
NSLog(@"%@", [WSerror localizedDescription]);
}
if (returnData) {
NSString *content = [NSString stringWithUTF8String:[myMutableData bytes]];
DebugLog(@"yeah %@", content);
}
I get no output from content string.
I think I am not calling the SOAP method correctly....?
What are your thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现您的代码存在一些问题:
connectionWithRequest:delegate:
创建并返回已初始化的 URL 连接,并开始加载 URL 请求的数据。
initWithRequest:委托:
返回一个初始化的 URL 连接并开始加载 URL 请求的数据。
sendSynchronousRequest:returningResponse:错误:
执行指定 URL 请求的同步加载。
请参阅: NSURLConnection 类参考< /a>
你为什么用同样的方法做这三个事情?两个异步 URL 连接和一个同步连接。
强烈建议不要在主线程上使用 sendSynchronousRequest。
您只需要一个 URL Connection 对象来发送 URL 请求的异步加载。注释掉之后的其余部分:
Change
myMutableData = [NSMutableData data]; myMutableData = [[NSMutableData alloc] init];
并实现
NSURLConnectionDelegate
方法来接收异步回调:I see some issues with your code:
connectionWithRequest:delegate:
Creates and returns an initialized URL connection and begins to load the data for the URL request.
initWithRequest:delegate:
Returns an initialized URL connection and begins to load the data for the URL request.
sendSynchronousRequest:returningResponse:error:
Performs a synchronous load of the specified URL request.
Refer: NSURLConnection Class Reference
Why are you doing all three in same method ? Two Asynchronous URL Connections and one Synchronous connection.
sendSynchronousRequest is strongly discouraged to be used on main thread.
You just need one URL Connection object to send asynchronous load of a URL Request. Comment out rest after:
Change
myMutableData = [NSMutableData data]; to myMutableData = [[NSMutableData alloc] init];
and implement
NSURLConnectionDelegate
methods to receive asynchronous call backs: