2013-03-12 62 views
0

我想從目標C做一個WCF服務調用。我在下面生成一個代碼,我再次從Web上的某個地方執行代碼。我無法弄清楚我會在哪裏提到要調用的特定方法。如何指定在來自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\"); 


} 

}

可以說我有一個方法iPhoneMethod()在服務服務1,我提這個呼叫哪裏?或者可能有一些其他的方式。是這樣在ajax調用中,「http:// [IP]/[服務路徑] /Service1.svc/iPhoneMethod」

回答

0

在WCF SOAP消息中,標題包含指定方法的SOAPAction。這定義了OperationContractAttribute.Action Property的值。

一般格式爲http://EndpointAddress/MethodName

因此,在短暫閱讀你的代碼(不知道目標C):

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

你需要tempuri.org更改爲實際的服務端點。

相關問題