嗨,我编写了简单的WCF服务并上传到我的本地IIS(v7)服务器中。所以网址就像那个http://mylink/WCF_SAMPLE/Service1.svc
.我的 WCF Web 服务是使用 SVCuil 测试的.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);
}
内部服务1.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网络服务以及如何获取showemployeename功能?
感谢任何帮助
最好的Rgds,东风
您正在将WCF_SAMPLE.Service1
服务配置为使用wsHttpBinding
而不是webHttpBinding
。这篇简短的博客文章给出了一个使用 webHttpBinding
的简单示例。