svc文件和有效的Web服务

时间:2013-08-12 05:41:05

标签: ios web-services nsurlrequest

我正在尝试将我的iPhone应用程序连接到我的Webservices。我对这个Web服务没有多少经验,所以这就是为什么我在这里要求提供信息/帮助。

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"
                     "<silent xmlns="http://tempuri.org/">"
                     "<action>logon</action>"
                     "<gameid>mygame</gameid>"
                     "<gpassword>gamepwd</gpassword>"
                     "<data>"
                     "<username>abc@abc.com</username>"
                     "<password>a</password>"
                     "</data>"
                     "</silent>"
                     "</soap:Body>"
                     "</soap:Envelope>"];



NSURL *url1 = [NSURL URLWithString:@"http://mywebsite.com/Service.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];

NSString *msgLength1 = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/ISilentManagerAPI/Service" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength1 forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

此代码始终返回status code 415,我做错了什么?

PS。

以下链接在Android getting java.io.IOException: HTTP request failed, HTTP status: 404 in ksoap2 while passing xml data to soap1.2 android

中正常运行

1 个答案:

答案 0 :(得分:0)

- 尝试这一点肯定会帮助你:

NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                             "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><Service xmlns=\"http://tempuri.org/\">"
                             "<xmlstring>&lt;silent&gt;&lt;action&gt;logon&lt;/action&gt;&lt;gameid&gt;mygame&lt;/gameid&gt;&lt;gpassword&gt;gamepwd&lt;/gpassword&gt;&lt;data&gt;&lt;username&gt;abcd@abc.com&lt;/username&gt;&lt;password&gt;a&lt;/password&gt;&lt;/data&gt;&lt;/silent&gt;</xmlstring></Service>"
                             "</SOAP-ENV:Body>"
                             "</SOAP-ENV:Envelope>"];

    NSURL *url1 = [NSURL URLWithString:@"http://mywebsite.com/Service.svc"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];
    NSString *msgLength1 = [NSString stringWithFormat:@"%d", [soapMessage length]];
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://tempuri.org/ISilentManagerAPI/Service" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength1 forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];