【问题标题】:occur error when i want to consume web service with SOAP当我想使用 SOAP 使用 Web 服务时发生错误
【发布时间】:2012-10-22 13:48:12
【问题描述】:

我创建了一个 Web 服务 (SampleService.asmx) 并在其中放入了一个返回字符串的方法 (GetAllUserInfo2)。我在Visual Studio 上测试并正常工作。

我使用下面的消息来消费它,我检查日志文件但发生错误

//Message
NSString *soapMessage=@"<?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"
     "<GetCategory xmlns=\"http://jahanmir.ir/\" />\n"
     "</soap:Body>\n"
     "</soap:Envelope>";

    NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:@"http://www.jahanmir.ir/SampleService.asmx"]];
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    //[theRequest addValue:@"http://jahanmir.ir/GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue:@"http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"];
    NSString *msgLength=[NSString stringWithFormat:@"%i",[soapMessage length]];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if(con)
        webData=[[NSMutableData data] retain];//webData is `NSMutableData` 

//Log
2012-10-22 17:39:50.533 WebServices[522:f803] data: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>

【问题讨论】:

    标签: objective-c xcode web-services soap ios4


    【解决方案1】:

    您的问题似乎在这一行[theRequest addValue:@"http://jahanmir.ir/GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"];

    您正在向根而不是 asmx 文件发出服务请求。这未经测试,但我想你会想为http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2 做广告标题

    【讨论】:

    • [theRequest addValue:@"http://jahanmir.ir/SampleService.asmx?op=GetAllUserInfo2" forHTTPHeaderField:@"SOAPAction"]; 看看是不是给你一个不同的错误,但那个 URL 直接转到你的服务。
    • 尝试再次将 URL 更改为 http://jahanmir.ir/SampleService.asmx 我猜,但您的服务似乎没有正确连接到服务的方法。
    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多