การส่งพารามิเตอร์ไปยังฟังก์ชัน WCF โดยใช้ Objective 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