Передача параметра в функцию WCF с использованием цели c

Кто-нибудь, пожалуйста, дайте мне знать, как передать параметр в функцию WCF, используя цель c?
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>  
  1. Я хотел бы использовать функцию «SearchUserData», передав текст поиска.

  2. WCF вернет XML-данные.


person John Thomas    schedule 17.04.2013    source источник
comment
Что вы пробовали? Вы даже искали похожие посты или темы? Используйте веб-службу WCF с помощью Objective-C на iPhone.   -  person Tim    schedule 17.04.2013
comment
И многое другое здесь — Вызов WCF с целью c   -  person Tim    schedule 17.04.2013
comment
Большое спасибо, Тим. Я уже пробовал искать содержимое по ссылкам, которые вы здесь упомянули. Большинство из них используют веб-сервис вместо WCF. Некоторые из них используют метод «Получить». Я новичок в задаче C. Не могли бы вы пролить свет на эту тему?   -  person John Thomas    schedule 17.04.2013
comment
WCF является веб-службой, заменой Microsoft их устаревших веб-служб (.ASMX) и удаленного взаимодействия. Метод Get звучит как REST (еще один тип веб-службы). Я никогда не работал в Objective-C, поэтому не могу предложить ничего, кроме ссылок, которые я разместил. Извини.   -  person Tim    schedule 17.04.2013
comment
Все в порядке, Тим. Ваша помощь приветствуется. Ждем еще комментариев :)   -  person John Thomas    schedule 17.04.2013


Ответы (1)


Этот код работает нормально.

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");
}
person islahul    schedule 23.04.2013