使用Objective c将参数传递给WCF函数 [英] Passing parameter to WCF function using Objective c
本文介绍了使用Objective c将参数传递给WCF函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人请告诉我如何使用目标c将参数传递给WCF函数?
1.我用C#开发WCF。
2. WCF端点如下。
Anybody please let me know how to pass parameter to WCF function using objective c?
1. I used C# to develop WCF.
2. WCF end point is as follows.
<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>
-
我想通过传递SearchUserData功能一个searchtext。
I would like to consume "SearchUserData" function by passing a searchtext.
WCF将返回XML数据。
WCF will return XML data.
推荐答案
此代码工作正常。
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");
}
这篇关于使用Objective c将参数传递给WCF函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文