我从我的xcode调试器调用.Net asmx web服务。在调试器中,我可以看到我传递了一些值但是在.net Web服务上它是空白的。
在Web服务端,我正在写入日志文件。我看到该方法被调用,但参数为空/空。我已粘贴下面的代码。我也粘贴了wsdl。参数变为空白的任何原因
-(void) fetchData: (NSString*)userid
{
NSString *requestSoapMsg =
[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"
"<UpdateRegForUser xmlns=\"http://soft.com\">\n"
"<userid>%@</userid>\n"
"</UpdateRegForUser>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", userid];
NSLog(@"%@", requestSoapMsg); // i can see the value here
NSURL *url = [NSURL URLWithString:@"http://soft.com:8000/services/registration.asmx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *requestSoapMsgLength = [NSString stringWithFormat:@"%d", [requestSoapMsg length]];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://soft.com/UpdateRegForUser" forHTTPHeaderField:@"SOAPAction"];
[request addValue:requestSoapMsgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[requestSoapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSError *error;
NSURLResponse *response;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(!result)
NSLog(@"FAILEDDDDDDDDD!!");
WSDL -
POST /services/registration.asmx HTTP/1.1
Host: soft.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://soft.com/UpdateRegForUser"
<?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/">
<soap:Body>
<UpdateRegForUser xmlns="http://soft.com/">
<userid>string</userid>
</UpdateRegForUser>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
我想出了问题。
我编写了一个C#控制台应用程序并调用了该Web服务。与此同时,我从提琴手那里捕捉到了痕迹。小提琴跟踪向我显示xmlns:soap =“http://schemas.xmlsoap.org/soap/envelope/”应该出现在xsi之前。我保存了xml并使我的请求xml完全相同。它开始工作了。