您好我是iOS应用程序和swift的新手,并且无法弄清楚如何在wsdl Web服务中使用swift。所以,我在spring web应用程序中创建了一些Web服务,并且能够在java中的某个客户端中使用Web服务。这是一个例子:
GroupService service = new GroupServiceService()
.getGroupServiceSoap11();
GetGroupRequest getGroupRequest = new GetGroupRequest();
getGroupRequest.setSearchString("abc");
GetGroupResponse response = service.getGroup(getGroupRequest);
for (RespondGroup rg : response.getRespondGroup()) {
System.out.println(rg.getGroupName());
}
现在,我想用快速语言在我的iphone应用程序中使用该服务。首先,我使用wsdl2objc工具创建了目标c类。然后,我得到它编译并能够使用swift控制器中的类。但是,我在网上找不到一个示例,告诉我如何在swift中使用该服务。这些是我可以在swift控制器中调用的类。
GroupServiceService GroupServiceService_getGroupRequest GroupServiceService_getGroupRespond GroupServiceService_respondGroup GroupServiceSoap11Binding GroupServiceSoap11Binding_envelope GroupServiceSoap11Binding_getGroup GroupServiceSoap11BindingOperation GroupServiceSoap11BindingResponse GroupServiceSoap11BindingResponseDelegate
根据wsdl2objc文件https://code.google.com/p/wsdl2objc/wiki/UsageInstructions,它仅显示如何在目标c中执行此操作。我应该在swift中做这样的事情
var binding:(GroupServiceService)GroupServiceSoap11Binding
var request:GroupServiceService_getGroupRequest
var response:GroupServiceSoap11BindingResponse
request.searchString = "abc"
response = binding.getGroupUsingGetGroupRequest(request)
response.bodyParts
有人能告诉我如何在swift中使用这些对象来做与在java客户端中做同样的事情吗?
或者,如果有人能指出我在swift中使用wsdl的更好方法吗?
由于
另外,我让它在目标C中工作。这是代码:
- (IBAction)button {
GroupServiceSoap11Binding* binding = [GroupServiceService GroupServiceSoap11Binding];
GroupServiceSoap11BindingResponse* response;
GroupServiceService_getGroupRequest* request = [[GroupServiceService_getGroupRequest alloc]init];
request.searchString = @"123";
response = [binding getGroupUsingGetGroupRequest:request];
dispatch_async(dispatch_get_main_queue(), ^{
[self processResponse:response];
});
}
-(void) processResponse: (GroupServiceSoap11BindingResponse*)soapResponse
{
NSArray *responseBodyParts = soapResponse.bodyParts;
id bodyPart;
bodyPart = [responseBodyParts objectAtIndex:0];
GroupServiceService_getGroupResponse *groupResponse = bodyPart;
NSArray *responseGroupList = [groupResponse respondGroup];
GroupServiceService_respondGroup *firstRespondGroup = [responseGroupList objectAtIndex:0];
NSLog(@"%@", firstRespondGroup.groupName);
}
只需要有人将其翻译成快速。
答案 0 :(得分:0)
我经过一些试验和错误后得到了它。可能会让它看起来更好。无论如何,就是这样:
var binding = GroupServiceService.GroupServiceSoap11Binding()
var request = GroupServiceService_getGroupRequest()
request.searchString = "UVA"
var response:GroupServiceSoap11BindingResponse = binding.getGroupUsingGetGroupRequest(request)
var responseBodyParts = response.bodyParts
var bodyPart = responseBodyParts[0] as! GroupServiceService_getGroupResponse
var responseGroupList = bodyPart.respondGroup
var firstRespondGroup = responseGroupList[0] as! GroupServiceService_respondGroup
println(firstRespondGroup.groupName)