2009-09-22 49 views
1

我正在开发一个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时效果很好。然后参数填入我输入的值。

回答

1

经过多次网络搜索,我找到了答案。

我使用工具SoapUI(http://www.soapui.org/)发送一些肥皂消息到我的web服务。 SoapUI显示了它发送给Web服务的XML消息,因此我发现iPhone应用程序中的消息语法不正确。

相反的:

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 
    ]; 

它是这样的:

NSString *soapMessage = [NSString stringWithFormat: 
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zdf=\"http://meijberg.topicus.local/zdfmobiel\">\n" 
"<soapenv:Body>\n" 
"<zdf:getVerzekerde>\n" 
"<zdf:bsn>%@</zdf:bsn>\n" 
"</zdf:getVerzekerde>\n" 
"</soapenv:Body>\n" 
"</soapenv:Envelope>\n", bsnInput.text 
]; 

不过,我真的不明白为什么这个工程..也许它有事情做与半所有标签中的冒号关键字。有人可以对此作出解释吗?

+0

我有同样的问题,但在我sceraio来电者是一个Windows应用程序创建soap xml并通过MSXML发送xml,你是否相信在我的情况下使用上述关键字可能会纠正问题? – Zich 2017-03-01 13:33:50

0

在这一行:

<getVerzekerde xmlns=\"http:/meijberg.topicus.local/zdfmobiel\"> 

你需要把一个斜线后的地址(zdfmobiel后):

<getVerzekerde xmlns=\"http:/meijberg.topicus.local/zdfmobiel/\"> 
+0

你可以发布这个作为编辑,从而让答案变得完整和自给自足吗? – Shreeni 2012-12-05 02:11:43