0

したがって、問題は、Endpoint.publish を使用してサービスと WSDL を公開する Java Webservice サーバーを (localhost で) セットアップし、手書きの SOAP 要求を localhost サーバーに送信しようとする iOS 6 プロジェクトをセットアップしたことです。

String を受け取り、int を返す「getCostForName」関数があります。iOS側では、私がやっていることは次のとおりです。

{
    NSString *soapMessage = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<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/\" xmlns=\"http://endpoints/\" >"
    "<soap:Body>"
    "<getCostForName>"
    "<name>Gdansk</name>"
    "</getCostForName>"
    "</soap:Body>"
    "</soap:Envelope>";

    NSURL *url = [NSURL URLWithString:@"http://localhost:9999/ws/wycieczka/"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://localhost:9999/ws/wycieczka/" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

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

    if( theConnection )
    {
        webData = [[NSMutableData data] retain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
    [connection release];
    [webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",theXML);
    [theXML release];

}

Java 側では、次のようになります。

    @Override
    public Integer getCostForName(String name) {
        System.out.println("getCostForName received:" + name);
        //Calculate the cost for a given name...
    }

Web サービス インターフェイスは、次の注釈によって定義されます。

@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC)

Web サービスは、次のエンドポイント パブリッシュ メソッドを使用してホストされます。

Endpoint.publish("http://localhost:9999/ws/wycieczka", new WycieczkaServiceImpl());

Java側では、ここに私が得るものがあります:

Nov 19, 2012 11:08:52 AM com.sun.xml.internal.ws.transport.http.HttpAdapter fixQuotesAroundSoapAction
getCostForName received:null
WARNING: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://localhost:9999/ws/wycieczka/

ご覧のとおり、サーバーは null 文字列を受け取ります。そして、なぜWebサービスを介して文字列を送信できないのか正確に理解できません:(だから、誰か、私が間違っていることを教えてください?

4

3 に答える 3

1

おそらくリクエストにSOAPヘッダーがないためだと思いますが、文字列連結を介してこれを行うことは本当に避けたいと思います。SOAP は非常に複雑なプロトコルであり、適切なクライアント実装が必要です。これを試して...

iPhone から SOAP サービスにアクセスする方法

于 2012-11-19T10:54:54.533 に答える
1

私は ksopa2 ver3 を使用して同じ問題を抱えていましたが、手書きの SOAP を使用していませんでした。www.wsdl2code.com から自動生成されたクラスを使用しました。線がありました

soapEnvelope.dotNet = true;

そのためのJavaファイルで、EndPoint用に生成されました。それをfalseに変更したところ、その後はうまくいきました。

アキル

于 2013-07-28T11:02:42.097 に答える
0

SOAP 1.1 仕様のセクション 6.1.1 に従って、SOAPAction HTTP ヘッダーには、URI 参照 (存在する場合) を二重引用符で囲む必要があります。

それが、この警告が表示される理由です。

WARNING: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://localhost:9999/ws/wycieczka/

次のようにする必要があります。

 [theRequest addValue: @"\"http://localhost:9999/ws/wycieczka/\"" forHTTPHeaderField:@"SOAPAction"];
于 2014-11-11T12:00:54.610 に答える