iOS 上的 SOAP 不工作

发布于 2025-01-05 09:12:53 字数 6182 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2025-01-12 09:12:53

我发现您的代码存在一些问题:

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection connectionWithRequest:request delegate:self];
NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request
                                          returningResponse:&WSresponse error:&WSerror];

connectionWithRequest:delegate:
创建并返回已初始化的 URL 连接,并开始加载 URL 请求的数据。

initWithRequest:委托:
返回一个初始化的 URL 连接并开始加载 URL 请求的数据。

sendSynchronousRequest:returningResponse:错误:
执行指定 URL 请求的同步加载。

请参阅: NSURLConnection 类参考< /a>

你为什么用同样的方法做这三个事情?两个异步 URL 连接和一个同步连接。

强烈建议不要在主线程上使用 sendSynchronousRequest。

您只需要一个 URL Connection 对象来发送 URL 请求的异步加载。注释掉之后的其余部分:

if (conn) {
        myMutableData = [NSMutableData data];
        NSLog(@"Conn is true");
    } 

Change myMutableData = [NSMutableData data]; myMutableData = [[NSMutableData alloc] init];

并实现 NSURLConnectionDelegate 方法来接收异步回调:

-(NSCachedURLResponse *)connection:(NSURLConnection *)connection
                 willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
  return nil;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   NSInteger statusCode = [httpResponse statusCode];
   NSLog(@"Http Status Code: %i",statusCode);
   if ([response respondsToSelector:@selector(statusCode)])
{
  int statusCode = [((NSHTTPURLResponse *)response) statusCode];
  if (statusCode >= 400)
  {
    [connection cancel];  // stop connecting; no more delegate messages
    NSDictionary *errorInfo
      = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:
          NSLocalizedString(@"Server returned status code %d",@""),
            statusCode]
                                    forKey:NSLocalizedDescriptionKey];
    NSError *statusError
      = [NSError errorWithDomain:@"HTTP Error"
                            code:statusCode
                        userInfo:errorInfo];
    [self connection:connection didFailWithError:statusError];
  }
}
   [myMutableData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
   [myMutableData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
   NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
   connection = nil;
   [myMutableData release],myMutableData = nil;
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   NSString *result =[[NSString alloc]initWithData:myMutableData encoding:NSUTF8StringEncoding];   
   NSLog(@"downloaded output  %@",result);

   [result release];
   [myMutableData release],myMutableData = nil;     
}

I see some issues with your code:

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection connectionWithRequest:request delegate:self];
NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request
                                          returningResponse:&WSresponse error:&WSerror];

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:

if (conn) {
        myMutableData = [NSMutableData data];
        NSLog(@"Conn is true");
    } 

Change myMutableData = [NSMutableData data]; to myMutableData = [[NSMutableData alloc] init];

and implement NSURLConnectionDelegate methods to receive asynchronous call backs:

-(NSCachedURLResponse *)connection:(NSURLConnection *)connection
                 willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
  return nil;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   NSInteger statusCode = [httpResponse statusCode];
   NSLog(@"Http Status Code: %i",statusCode);
   if ([response respondsToSelector:@selector(statusCode)])
{
  int statusCode = [((NSHTTPURLResponse *)response) statusCode];
  if (statusCode >= 400)
  {
    [connection cancel];  // stop connecting; no more delegate messages
    NSDictionary *errorInfo
      = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:
          NSLocalizedString(@"Server returned status code %d",@""),
            statusCode]
                                    forKey:NSLocalizedDescriptionKey];
    NSError *statusError
      = [NSError errorWithDomain:@"HTTP Error"
                            code:statusCode
                        userInfo:errorInfo];
    [self connection:connection didFailWithError:statusError];
  }
}
   [myMutableData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
   [myMutableData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
   NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
   connection = nil;
   [myMutableData release],myMutableData = nil;
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   NSString *result =[[NSString alloc]initWithData:myMutableData encoding:NSUTF8StringEncoding];   
   NSLog(@"downloaded output  %@",result);

   [result release];
   [myMutableData release],myMutableData = nil;     
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文