Iphone 使用目标c将参数传递给WCF函数
有人请告诉我如何使用objective c将参数传递给WCF函数吗?Iphone 使用目标c将参数传递给WCF函数,iphone,objective-c,xcode,ios6,Iphone,Objective C,Xcode,Ios6,有人请告诉我如何使用objective c将参数传递给WCF函数吗? 1.我使用C#开发WCF。 2.WCF终点如下所示 <system.serviceModel> <services> <service name="iAppServ.Service1" behaviorConfiguration="ServBehave"> <!--Endpoint for SOAP--> <endpoint addres
1.我使用C#开发WCF。
2.WCF终点如下所示
<system.serviceModel>
<services>
<service name="iAppServ.Service1" behaviorConfiguration="ServBehave">
<!--Endpoint for SOAP-->
<endpoint address="soapService" binding="basicHttpBinding" contract="iAppServ.IService1"/>
<!--Endpoint for REST-->
<endpoint address="XMLService" binding="webHttpBinding" behaviorConfiguration="restPoxBehavior" contract="iAppServ.IService1"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding crossDomainScriptAccessEnabled="True" name="webHttpBinding">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServBehave" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<!--Behavior for the REST endpoint for Help enability-->
<behavior name="restPoxBehavior" >
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
NSString *soapMessage = [NSString stringWithFormat:@"<SearchUserData xmlns=\"http://tempuri.org/\"><SearchText>"];
soapMessage=[soapMessage stringByAppendingString:searchBar.text];
soapMessage=[soapMessage stringByAppendingString:@"</SearchText> </SearchUserData> "];
NSURL *url = [NSURL URLWithString:@"http://your server.svc/XMLService/SearchUserData"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-16" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/IService1/SearchUserData" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
// NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection) {
NSError *WSerror;
NSURLResponse *WSresponse;
NSString *theXml;
NSData *myData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&WSresponse error:&WSerror];
theXml = [[NSString alloc]initWithBytes:[myData bytes] length:[myData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXml);
}
else {
NSLog(@"theConnection is NULL");
}
NSString*soapMessage=[NSString stringWithFormat:@”“;
soapMessage=[SOAPMessageStringByAppendingString:searchBar.text];
soapMessage=[SOAPMessageStringByAppendingString:@”“];
NSURL*url=[NSURL URLWithString:@”http://your server.svc/XMLService/SearchUserData“];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-16”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”http://tempuri.org/IService1/SearchUserDataforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
//NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:request委托:self];
if(连接){
n错误*WSerror;
NSURLResponse*WSresponse;
NSString*theXml;
NSData*myData=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&WSresponse error:&WSerror];
XML=[[NSString alloc]initWithBytes:[myData bytes]长度:[myData length]编码:NSUTF8StringEncoding];
NSLog(@“%@”,XML);
}
否则{
NSLog(@“连接为空”);
}
此代码工作正常
NSString *soapMessage = [NSString stringWithFormat:@"<SearchUserData xmlns=\"http://tempuri.org/\"><SearchText>"];
soapMessage=[soapMessage stringByAppendingString:searchBar.text];
soapMessage=[soapMessage stringByAppendingString:@"</SearchText> </SearchUserData> "];
NSURL *url = [NSURL URLWithString:@"http://your server.svc/XMLService/SearchUserData"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-16" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/IService1/SearchUserData" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
// NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection) {
NSError *WSerror;
NSURLResponse *WSresponse;
NSString *theXml;
NSData *myData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&WSresponse error:&WSerror];
theXml = [[NSString alloc]initWithBytes:[myData bytes] length:[myData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXml);
}
else {
NSLog(@"theConnection is NULL");
}
NSString*soapMessage=[NSString stringWithFormat:@”“;
soapMessage=[SOAPMessageStringByAppendingString:searchBar.text];
soapMessage=[SOAPMessageStringByAppendingString:@”“];
NSURL*url=[NSURL URLWithString:@”http://your server.svc/XMLService/SearchUserData“];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-16”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”http://tempuri.org/IService1/SearchUserDataforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
//NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:request委托:self];
if(连接){
n错误*WSerror;
NSURLResponse*WSresponse;
NSString*theXml;
NSData*myData=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&WSresponse error:&WSerror];
XML=[[NSString alloc]initWithBytes:[myData bytes]长度:[myData length]编码:NSUTF8StringEncoding];
NSLog(@“%@”,XML);
}
否则{
NSLog(@“连接为空”);
}
您尝试过什么?你有没有搜索过相关的帖子或主题。还有更多,谢谢你,蒂姆。我已经尝试过从你在这里提到的链接中搜索内容。他们中的大多数人使用web服务而不是WCF。他们中的一些人正在使用“Get”方法。我不熟悉objective C。你能解释一下这个话题吗?WCF是一种web服务,它是Microsoft对其传统web服务(.ASMX)和远程处理的替代品。Get方法听起来像REST(另一种类型的web服务)。我从来没有在Objective-C工作过,所以除了我发布的链接之外,我真的不能提供太多。对不起,没关系,蒂姆。谢谢你的帮助。等待更多评论:)您尝试了什么?你有没有搜索过相关的帖子或主题。还有更多,谢谢你,蒂姆。我已经尝试过从你在这里提到的链接中搜索内容。他们中的大多数人使用web服务而不是WCF。他们中的一些人正在使用“Get”方法。我不熟悉objective C。你能解释一下这个话题吗?WCF是一种web服务,它是Microsoft对其传统web服务(.ASMX)和远程处理的替代品。Get方法听起来像REST(另一种类型的web服务)。我从来没有在Objective-C工作过,所以除了我发布的链接之外,我真的不能提供太多。对不起,没关系,蒂姆。谢谢你的帮助。正在等待更多评论:)