【问题标题】:Call WCF Web Service using ASIHttprequest XCode4.2使用 ASIHttprequest XCode4.2 调用 WCF Web 服务
【发布时间】:2012-10-06 07:20:04
【问题描述】:

您好,我编写了简单的 WCF 服务并上传到我的本地 IIS(v7) 服务器。 所以网址就像http://mylink/WCF_SAMPLE/Service1.svc。我的 wcf web 服务是用 svcutil.exe 测试的,所以 wcf web 服务是正确的。

我尝试使用来自 AsiHttprequest 的 WCF Web 服务。但它失败了。我检查了显示<object returned empty description> 的响应。这是我为 IOS 应用程序编写的代码。

 NSURL *url=[NSURL URLWithString:@"http://mylink/WCF_SAMPLE/Service1.svc"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];
[request setPostValue:@"john" forKey:@"fname"];
[request setPostValue:@"Carter" forKey:@"sname"];
[request setDelegate:self]; 
[request startAsynchronous]; 

这是我在 IService1.cs 中的 Web 服务代码:

[ServiceContract]
public interface IService1{
   [OperationContract]
   [WebInvoke(Method="POST",UriTemplate="/showemployeename")]
   string showemployeename(string fname,string sname);
}

Service1.svc.cs 内部

public class Service1:IService1{
 public string showemployeename(string fname,string sname)
 {
    return fname+sname
 }
}

这是我的 web.config 文件

<system.serviceModel>
  <services>
   <service name="WCF_SAMPLE.Service1" behaviorConfiguration="WCF_SAMPLE.Service1Behavior">
       <endpoint address="" binding="wsHttpBinding" contract="WCF_SAMPLE.IService1">
       </endpoint>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behavior name="WCF_SAMPLE.Service1Behavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false"/>
   </behavior></system.serviceModel>

如何连接WCF web服务以及如何获取showemployeename函数?

感谢任何帮助

最佳 Rgds, df

【问题讨论】:

    标签: c# wcf ios5 xcode4 asihttprequest


    【解决方案1】:

    您将WCF_SAMPLE.Service1 服务配置为使用wsHttpBinding 而不是webHttpBinding。这个short blog post 给出了一个使用webHttpBinding 的简单示例。

    【讨论】:

    • 您好,感谢您的宝贵时间。你的意思是 webHttpBinding 而不是 wsHttpBinding ?
    • 对,您的配置显示binding="wsHttpBinding",并且您的服务联系人标有WebInvoke,它特定于WebHttpBinding。如果您按照示例链接中所示重新配置配置文件,您的 iOS 客户端应该会接收作为标准 XML 而不是肥皂格式的 XML 消息的返回字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 2015-11-15
    相关资源
    最近更新 更多