从xcode4.3调用wcf服务

从xcode4.3调用wcf服务

问题描述:

我是.Net程序员,也是Xcode的初学者。我想在UITableViewController的iPad上显示WCF服务的结果。我已经使用wsdl2objc成功创建了该服务的存根。创建的SOAP消息如下:从xcode4.3调用wcf服务

2012-07-25 14:02:37.169 TestWCF[5280:fb03] OutputHeaders: 
{ 
    "Content-Length" = 572; 
    "Content-Type" = "text/xml; charset=utf-8"; 
    Host = "XXX.XXX.XXX"; 
    SOAPAction = "http://tempuri.org/IDocSync/getAllCategories"; 
    "User-Agent" = wsdl2objc; 
} 
2012-07-25 14:02:37.172 TestWCF[5280:fb03] OutputBody: 
<?xml version="1.0"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns:iPadDocSyncServiceSvc="http://tempuri.org/" xmlns:ns1="http://tempuri.org/Imports" xmlns:tns1="http://schemas.datacontract.org/2004/07/DocSyncService" xmlns:tns2="http://schemas.microsoft.com/2003/10/Serialization/" xsl:version="1.0"> 
<soap:Body> 
<iPadDocSyncServiceSvc:getAllCategories/> 
</soap:Body> 
</soap:Envelope> 
2012-07-25 14:03:03.119 TestWCF[5280:fb03] ResponseStatus: 200 
2012-07-25 14:03:03.120 TestWCF[5280:fb03] ResponseHeaders: 
{ 
    "Cache-Control" = private; 
    "Content-Encoding" = gzip; 
"Content-Length" = 421; 
"Content-Type" = "text/xml; charset=utf-8"; 
    Date = "Wed, 25 Jul 2012 06:03:02 GMT"; 
Server = "Microsoft-IIS/7.5"; 
"Set-Cookie" = "ASP.NET_SessionId=55w4noiub50zqtqclwdx3ral; path=/; HttpOnly"; 
    Vary = "Accept-Encoding"; 
    "X-AspNet-Version" = "4.0.30319"; 
    "X-Powered-By" = "ASP.NET"; 
} 
2012-07-25 14:03:03.121 TestWCF[5280:fb03] ResponseBody: 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Body> 
    <getAllCategoriesResponse xmlns="http://tempuri.org/"> 
     <getAllCategoriesResult  xmlns:a="http://schemas.datacontract.org/2004/07/DocSyncService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
       <a:Category> 
        <a:categoryId>4</a:categoryId> 
        <a:categoryName>IT</a:categoryName> 
        <a:categoryType>0</a:categoryType> 
        <a:docCount>3</a:docCount> 
        <a:subCategoryId>0</a:subCategoryId> 
       </a:Category> 
       <a:Category> 
        <a:categoryId>6</a:categoryId> 
        <a:categoryName>CPG</a:categoryName> 
        <a:categoryType>0</a:categoryType> 
        <a:docCount>1</a:docCount> 
        <a:subCategoryId>0</a:subCategoryId> 
       </a:Category> 
     </getAllCategoriesResult> 
    </getAllCategoriesResponse> 
</s:Body> 
</s:Envelope> 

在Appdelegate.m的代码是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    BasicHttpBinding_IDocSyncBinding *myBinding = [iPadDocSyncServiceSvc BasicHttpBinding_IDocSyncBinding]; 
myBinding.logXMLInOut = YES; 

//iPadDocSyncServiceSvc_getAllCategories *allCate =  [[iPadDocSyncServiceSvc_getAllCategories new]autorelease]; 
iPadDocSyncServiceSvc_getAllCategories *allCate = [[iPadDocSyncServiceSvc_getAllCategories  alloc]init]; 

BasicHttpBinding_IDocSyncBindingResponse *response = [myBinding getAllCategoriesUsingParameters:allCate]; 

for(id bodyPart in response.bodyParts) 
{ 
    //if([bodyPart isKindOfClass:[BasicHttpBinding_IDocSyncBindingResponse class]]) 
    //{ 
    //tns1_ArrayOfCategory *cateClass = (tns1_ArrayOfCategory *) bodyPart; 
    //[self.tableView reloadData]; 

    //categories = (NSMutableArray *) cateClass; 
    //tns1_ArrayOfCategory *cateClass = [bodyPart getAllCategoriesResult]; 

    self.categories = (NSMutableArray *) [bodyPart getAllCategoriesResult]; 
    //} 
} 


return YES; 
} 

当我运行此,没有显示在模拟器......它显示了一个空白屏幕。有一件事很明显,我错过了。我怎样才能使它工作?

+0

代码中的任何更正? – user1550951 2012-07-26 02:57:34

我写了几篇使用Wsdl2Objc的教程,也许他们可以帮助。

http://brismith66.blogspot.com/search/label/iPhone%20Development

+0

: - 我遵循你的例子,它的工作原理。但是我想实现的有点不同。教程示例返回标记中的单个值。我的工作在采样返回对象的数组(复杂类型)。所以,我标签看起来像: someValue中 anothervalue值1。我想在表格中显示“一些值”和“值”。我如何实现这一目标? – user1550951 2012-08-08 01:39:40

+0

@ from.NetToiOS您需要检查Wsdl2obj创建的代码。特别是,它会创建一个对应于的类(它可能会被命名为 _ 响应,并且在该类内部,您可能会看到对应于的对象数组 – brismith 2012-08-08 14:47:54