我正在开发一个iPhone应用程序,它将SOAP消息发送到.NET Webservice以调用多个WebMethods。这些方法从数据库中获取数据并在SOAP消息中将其返回给iPhone。Webmethod参数保留null
当我发送SOAP消息调用没有任何参数的WebMethod时,它工作得很好。
但是,当我通过消息传递参数时,webMethod参数在Visual Studio调试器中保持为空。它看起来像WebMethod没有收到任何东西。
我使用网络嗅探器来查看传入数据包,并注意到SOAP消息到达时可以使用。所以它必须是web服务端出现问题的地方。
这里是一些代码:
的的WebMethod:
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>
任何人知道问题可能是什么?
编辑:当我从网页服务器自动生成的网页调用webmethod时效果很好。然后参数填入我输入的值。
我有同样的问题,但在我sceraio来电者是一个Windows应用程序创建soap xml并通过MSXML发送xml,你是否相信在我的情况下使用上述关键字可能会纠正问题? – Zich 2017-03-01 13:33:50