0

我正在尝试从 Objective C 进行 WCF 服务调用。我正在生成下面的代码,这也是我从网络上的某个地方获取的。我不知道我会在哪里提到要调用的特定方法。

-(void)viewDidLoad {

[super viewDidLoad];

//Web Service Call
NSString *soapMessage = [NSString stringWithFormat:

                         @\"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>\n\"

                         \"<SOAP-ENV:Envelope \n\"
                         \"xmlns:xsd=\\"http://www.w3.org/2001/XMLSchema\\" \n\"
                         \"xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" \n\" 
                         \"xmlns:SOAP-ENC=\\"http://schemas.xmlsoap.org/soap/encoding/\\" \n\"


                         \"SOAP-ENV:encodingStyle=\\"http://schemas.xmlsoap.org/soap/encoding/\\" \n\"


                         \"xmlns:SOAP-ENV=\\"http://schemas.xmlsoap.org/soap/envelope/\\"> \n\"


                         \"<SOAP-ENV:Body> \n\"

                         \"<GetMembers mlns=\\"http://tempuri.org/\\">\"


                         \"</GetMembers> \n\"                            \"</SOAP-ENV:Body> \n\"

                         \"</SOAP-ENV:Envelope>\"]; 

//[[NSURLCache sharedURLCache] removeAllCachedResponses];

NSURL *url = [NSURL URLWithString:@\"http://[IP_ADDRESS_OF_WCF_SERVER]/IphoneService/Service1.svc\"];                           


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/IService1/GetMembers\" 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\");


}

}

假设我在服务 Service1 中有一个方法 iPhoneMethod(),我在调用中在哪里提到这个?或者可能有其他方法。是不是像在 ajax 调用中那样,“http://[IP]/[Service Path]/Service1.svc/iPhoneMethod”

4

1 回答 1

0

在 WCF SOAP 消息中,标头包含SOAPAction指定方法的 a。这定义了OperationContractAttribute.Action Property的值。

一般格式为http://EndpointAddress/MethodName.

因此,在简要阅读您的代码时(并且不知道目标 c):

[theRequest addValue: @\"http://tempuri.org/IService1/GetMembers\" forHTTPHeaderField:@\"Soapaction\"];

您需要将 tempuri.org 更改为实际的服务端点。

于 2013-03-15T16:22:14.257 回答