1

目的の c を使用してパラメーターを WCF 関数に渡す方法を教えてください。
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 データを返します。

4

1 に答える 1

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");
}
于 2013-04-23T06:52:03.823 に答える