【发布时间】:2009-09-22 08:24:08
【问题描述】:
我正在开发一个 iPhone 应用程序,它将 SOAP 消息发送到 .NET Web 服务以调用多个 WebMethods。这些方法从数据库中获取数据并在 SOAP 消息中将其返回给 iPhone。
当我发送一个 SOAP 消息调用没有任何参数的 WebMethod 时,它工作得很好。
但是当我通过消息传递参数时,webMethod 参数在 Visual Studio 调试器中保持为空。看起来 WebMethod 没有收到任何东西。
我使用网络嗅探器查看传入的数据包,发现 SOAP 消息在进来时是正常的。所以一定是 web 服务端出了问题。
这里有一些代码:
网络方法:
public class ZDFMobielWebservice : System.Web.Services.WebService
{
[WebMethod]
public string getVerzekerde(string bsn)
{
string result = bsn;
ZDFKoppeling koppeling = new ZDFKoppeling();
result = koppeling.getData(Convert.ToInt32(bsn));
return result;
}
}
创建 SOAP 消息的函数:
-(IBAction)buttonClick:(id)sender
{
recordResults = FALSE;
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"
"<getVerzekerde xmlns=\"http:/meijberg.topicus.local/zdfmobiel\">\n"
"<bsn>%@</bsn>\n"
"</getVerzekerde>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", bsnInput.text
];
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://meijberg.topicus.local/ZDFMobielWebservice.asmx"];
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://meijberg.topicus.local/zdfmobiel/getVerzekerde" 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");
}
//[nameInput resignFirstResponder];
}
这里是 SOAP 消息:
<?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>
<getVerzekerde xmlns="http:/meijberg.topicus.local/zdfmobiel">
<bsn>999999999</bsn>
</getVerzekerde>
</soap:Body>
</soap:Envelope>
有谁知道问题出在哪里?
编辑:当我从网络服务器自动生成的网页调用网络方法时,它运行良好。然后用我输入的值填充参数。
【问题讨论】: