gpt4 book ai didi

iphone - 在 iPhone 上使用 Objective-C 使用 WCF Web 服务

转载 作者:IT老高 更新时间:2023-10-28 11:48:09 26 4
gpt4 key购买 nike

我很难在我的 iPhone 应用程序中使用一个非常简单的 (Hello World) WCF Web 服务。根据我的阅读,您必须手动创建请求消息,然后将其发送到 Web 服务 URL。

我能够在 .asmx Web 服务上完成此操作,但不能使用 WCF 服务。

我如何知道请求 SOAP 消息的正确格式?

我尝试访问的网络服务具有以下格式: http://xxx.xxx.xxx.xxx:PORT/IService1/ (在虚拟机中本地运行)

我很抱歉缺少信息,我很迷茫。

非常感谢任何和所有的帮助。

最佳答案

感谢所有在这里提供帮助的人。我最终弄清楚了,并认为我会分享我的结果。我知道这不是一个全面的解决方案,所以如果您需要更多详细信息,请给我留言或评论。

//Variables used
NSMutableData *webData;
NSMutableString *soapResults;
NSXMLParser *xmlParser;
BOOL recordResults;

//Web Service Call
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"<SOAP-ENV:Body> \n"
"<Login xmlns=\"http://tempuri.org/\"><username>JACKSON</username><password>PASSWORD</password>"
"</Login> \n"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://172.16.0.142:8731/Service1/"];
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://tempuri.org/IService1/Login" 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");
}

//Implement the NSURL and XMLParser protocols
#pragma mark -
#pragma mark NSURLConnection methods

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

#pragma mark -
#pragma mark XMLParser methods

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName

关于iphone - 在 iPhone 上使用 Objective-C 使用 WCF Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/982622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com