所以,问题是,我已经(在 localhost 上)设置了一个 Java Webservice 服务器,它使用 Endpoint.publish 来发布服务,它是 WSDL,以及尝试向 localhost 服务器发送手写 SOAP 请求的 iOS 6 项目。
我有一个接收字符串并返回 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...
}
webservice接口由以下注解定义:
@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/
因此,如您所见,服务器接收到空字符串。而且我不知道为什么我不能通过网络服务传输字符串:(那么,有人可以告诉我我做错了什么吗?