使用Android的WCF
我有一个WCF API,当Windows应用程序使用web服务引用调用它时,它正在IIS上工作。当被Android应用程序调用时,我并没有试图让它工作。我假设我可以从web浏览器或Fiddler“测试”其他方面工作的API,以确保我的调用语法是正确的,但是当我尝试时,我得到了404错误 我的Webservice Web.config服务模型如下所示:使用Android的WCF,wcf,Wcf,我有一个WCF API,当Windows应用程序使用web服务引用调用它时,它正在IIS上工作。当被Android应用程序调用时,我并没有试图让它工作。我假设我可以从web浏览器或Fiddler“测试”其他方面工作的API,以确保我的调用语法是正确的,但是当我尝试时,我得到了404错误 我的Webservice Web.config服务模型如下所示: <system.serviceModel> <protocolMapping> <add scheme="ht
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding"/>
</protocolMapping>
<services>
<service name="TaskTrackerAppService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="TaskTrackerAppService.IAppWebService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration=""></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
我确实得到了预期的WSDL响应。(从我的本地主机和运行此WCF的托管web服务器。)
因此,接下来我添加以下请求:
http://localhost:51276/AppWebService.svc/SayHello/1000
其中SayHello将返回用户ID 1000存在的确认。我回来了:
404 - The resource cannot be found
我也试过:
http://localhost:51276/AppWebService.svc/SayHello?userId=1000 etc.
救命啊。我卡住了。如您所知,我们需要生成客户端代理类来调用传统的wcf服务。我们可以使用以下方法。 1.添加服务引用。或者使用svcutil.exe生成客户端代理类。 2.使用通道工厂。 而这些方法都需要客户端代理类。如果希望以URL的形式调用特定操作,则需要以http web模式承载WCF。这要求我们使用webservicehost或webhttpbinding。我做了一个演示。希望它对你有用。 服务器 结果。
有关wcf web http模式服务(Restful)的更多详细信息。
您有一个
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
但是没有一个端点使用它
选择端点并使用此行为。现在,它是死的,未使用的XML
class Program
{
static void Main(string[] args)
{
WebServiceHost host = new WebServiceHost(typeof(MyService));
host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "http://localhost:9090");
host.Open();
Console.WriteLine("Service is ready");
Console.ReadKey();
host.Close();
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
string SayHi(int id);
}
public class MyService : IService
{
public string SayHi(int id)
{
Console.WriteLine("Wow, I have been called");
return "Hello Stranger "+id;
}
}
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>