2009-12-12 167 views
0

我正在从iPhone上的图像上传到C#web服务。下面是iPhone的代码缓冲区不能为空参数:缓冲区

NSString *soapMessage=[NSString stringWithFormat: 
         @"<?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/\">\n" 
         "<soap:Body>\n" 
         "<PutImage xmlns=\"http://tempuri.org/\">\n" 
         "<ImgInputString>%@</ImgInputString>\n" 
         "</PutImage>\n" 
         "</soap:Body>\n" 
"</soap:Envelope>\n",imageString]; 

NSLog(soapMessage); 
NSURL *url=[NSURL URLWithString:@"http://192.168.2.7/ImageWebService/Service1.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://tempuri.org/PutImage" forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

但是当我访问服务器我收到此错误信息。但是,当我直接复制并粘贴图像字符串在web服务中,我得到的图像。它只是从iPhone上抛出错误。

请帮

+0

您是否试图通过使用例如HTTP请求来找出HTTP请求之间的差异?一个调试HTTP代理或一个HTTP嗅探器? –

回答

0

我有麻烦与此同样,我相信这是编码,(具体MS服务器?)这里是我的建议。

[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]]; 
0

我得到这个解决。我改变了我的服务器端输入为字符串(bas64字符串),但我打的网络服务不是更新的,是以前的byte []输入。所以,我把我的web服务的DLL在inetpub/wwwroot/bin中挂到了新的chnaged web服务.dll。现在它像一个魅力。

和NWCoder,您可以将您的字符串加密为base64编码,并将其作为字符串发送到您的c#web serice,然后将i转换为byte []。这对我来说很顺利。任何方式thsnks您的建议。