如何编写xml的soap消息 [英] how to write xml for soap message

查看:112
本文介绍了如何编写xml的soap消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的在iphone的网络服务。



我需要从.net服务器获取数据。



我不允许此教程 a>



在此soap消息中是

  NSString * soapMessage = [NSString stringWithFormat:
@<?xml version = \1.0 \encoding = \utf-8\?> \\\

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/\> \\\

< soap:Body> \\\

< ; Hello xmlns = \http://viium.com/\> \\\

< name>%@< / name> \\\

< ; / Hello> \ n
< / soap:Body> \\\

< / soap:Envelope> \\\
,nameInput.text
];

但我没有这方面的知识,



我来自于java背景。



在Android中,我的xml字符串是

  xml =< MortgageGetLoanOfficerInfo>< PhoneNumber>+ getDeviceTelNo()+< / PhoneNumber>< / MortgageGetLoanOfficerInfo& 

如何在iphone中写这个。


解决方案

可以任何pls post解决方案。



<

您正在NSString中正确分配您的soap请求。现在您必须创建NSMutableURLRequest对象并按如下方式发送请求:

  NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:webServiceUrl]; 

NSString * msgLength = [NSString stringWithFormat:@%d,[soapMessage length]];
[req addValue:@text / xml; charset = utf-8forHTTPHeaderField:@Content-Type];
[req addValue:yourSoapAction forHTTPHeaderField:@SOAPAction];
[req addValue:msgLength forHTTPHeaderField:@Content-Length];
[req setHTTPMethod:@POST];
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSHTTPURLResponse * urlResponse = nil;
NSError * error = [[[NSError alloc] init] autorelease];
NSData * webData = [NSURLConnection sendSynchronousRequest:req returningResponse:& urlResponse error:& error];



现在使用任何xml解析器解析您的webData。我通常喜欢NSXMLParser



希望这有帮助..


I am new to web services in iphone.

I need to get data from .net server.

I fallow this tutorial

In this soap message is

NSString *soapMessage = [NSString stringWithFormat:
    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    "<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/\">\n"
    "<soap:Body>\n"
    "<Hello xmlns=\"http://viium.com/\">\n"
    "<name>%@</name>\n"
    "</Hello>\n"
    "</soap:Body>\n"
    "</soap:Envelope>\n", nameInput.text
    ];

But i did n't have knowledge on this,

I am from java background.

In android my xml string is

xml="<MortgageGetLoanOfficerInfo><PhoneNumber>"+getDeviceTelNo()+"</PhoneNumber></MortgageGetLoanOfficerInfo>";

how can i write this in iphone.

can any pls post solution.

Thank u in advance.

解决方案

You are correctly assigning your soap request in NSString. Now you have to create NSMutableURLRequest object and send the request as follow

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:webServiceUrl];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];              
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:yourSoapAction forHTTPHeaderField:@"SOAPAction"];
[req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];    
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[[NSError alloc] init] autorelease];  
NSData *webData = [NSURLConnection sendSynchronousRequest:req returningResponse:&urlResponse error:&error]; 

Now parse your webData using any of xml parser. I generally prefer NSXMLParser

Hope this helped..

这篇关于如何编写xml的soap消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆