2012-02-19 21 views
1

SOAPリクエストを使用して、National Digital Forecast Database(NDFD)から毎日の天気予報にアクセスしようとしています。 SOAPのURLはiOSのNDFD SOAPリクエスト

http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php 

あるとNDFDgenByDay()のためのSOAPアクションは、私がリクエストを送信すると

http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay. 

は、私が受け取るXMLにエラーが発生したことを示している、と私はそれが関係していると考えています私のHTTPヘッダー。エラー応答を以下に示します。

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SERVER</faultcode> <faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">format needs to be either 24 hourly or 12 hourly</faultstring><detail xsi:type="xsd:string">input  format was &quot;&quot;</detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope> 

このエラーは "format"値には当てはまりますが、以下に示すように、私のxmlはこれに準拠しています。

以下に示すように、私はiOSの/ OBJの-Cにリクエストを送信しています:私はsoapRequestその半確信していますsoapRequest.xmlが

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
    <ns6244:NDFDgenByDay xmlns:ns6244="uri:DWMLgenByDay"> 
     <latitude xsi:type="xsd:string">38.99</latitude> 
     <longitude xsi:type="xsd:string">-77.01</longitude> 
     <startDate xsi:type="xsd:string">2012-03-12</startDate> 
     <numDays xsi:type="xsd:string">7</numDays> 
     <format xsi:type="xsd:string">24 hourly</format> 
    </ns6244:NDFDgenByDay> 
</SOAP-ENV:Body> 

のように見えます

NSString *path = [[NSBundle mainBundle] pathForResource:@"soapRequest" ofType:@"xml"]; 
    NSString *soapContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL]; 

    NSURL *url = [NSURL URLWithString:kWeatherSOAP_URL]; 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapContent length]]; 

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue:@"NDFDgenByDay" forHTTPHeaderField:@"Name"]; 
    [theRequest addValue:@"ndfdXMLBinding" forHTTPHeaderField:@"Binding"]; 
    [theRequest addValue:@"http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php" forHTTPHeaderField:@"Endpoint"]; 
    [theRequest addValue: @"http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay" forHTTPHeaderField:@"SoapAction"]; 
    [theRequest addValue:@"rpc" forHTTPHeaderField:@"Style"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody: [soapContent dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if (theConnection) 
     receivedData = [NSMutableData data]; 
    else 
     NSLog(@"theConnection is NULL"); 

を.xmlは、NDFDのWebサイトにsample codeとして掲載されているため、正しいです。しかし、私はHTTPヘッダーを設定する正しい方法を知らない。誰かがこれに精通しているか、問題の内容を知っている場合は、私を助けてください。私はFFにsoapRequest.xmlを変更することにより、作業プログラムを持っ

答えて

1

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body> 
     <ns6244:NDFDgenByDay xmlns:ns6244="uri:DWMLgenByDay"> 
      <latitude xsi:type="xsd:decimal">38.99</latitude> 
      <longitude xsi:type="xsd:decimal">-77.01</longitude> 
      <startDate xsi:type="xsd:date">2012-08-07</startDate> 
      <numDays xsi:type="xsd:integer">7</numDays> 
      <Unit xsi:type="xsd:string">m</Unit> 
      <format xsi:type="xsd:string">24 hourly</format> 
     </ns6244:NDFDgenByDay> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
+0

いくつかのものは非常に簡単です...おかげで自分自身とあなたのコードは私がこぶを乗り越える助けた私がSOAPを学んでいた – alexshafran

+0

VIPMあなたもありがとう、CodeCarrigan – vipm

+0

それをデバッグすると、まずフォーマットの後にUnitを追加しました。私は別のエラーを持って、それは 'm'が間違ったフォーマットだと言いました。だから私はそれが間違ったフォーマットであると言っていたときとは違って、ユニットの内容を読んでいることを知っていました。だから私はユニットのフィールドをフォーマットの上に移動し、それがうまくいったのです。最終的にiOS上でSOAPを動作させるために8時間以上かかりました。私は7時間目にあなたのコードを見つけました。 – vipm

関連する問題