【发布时间】:2011-05-29 07:57:43
【问题描述】:
我有一个使用 IIS 托管在远程服务器上的 WCF 服务。我想让这项服务与 android 兼容,这样我就可以在 android 客户端上使用该服务。我遇到的问题是我正在尝试使用 ksoap2 连接到服务,但每次尝试调用该方法时都会出现 400 错误。我已经使用 fiddler2 来尝试查看问题所在,除了 400 错误之外,它还发送回 content-length: 0 (不知道这是否是原因。有趣的事实是,当我指定内容时-length 在提琴手的请求中,它不会给我 400 错误,而是根本不返回响应)我已经尝试将绑定更改为 webHttpBinding 而不是 wsHttpBinding 并在方法上方添加 WebGet 属性使用 URITemplate、BodyStyle 等,但没有运气。这是我的代码:
服务
public class PublicService : IPublicService
{
public Wallpaper[] GetWallpapers()
{
//return _wallpaperRepository.Items.ToArray();
return new Wallpaper[]{ new Wallpaper()
{
Id = 10
}};
}
}
界面
[ServiceContract(Namespace = "http://XXXXXXXX.com/ServiceA")]
public interface IPublicService
{
[OperationContract]
Wallpaper[] GetWallpapers();
}
Web.Config
<bindings>
<wsHttpBinding>
<binding name="android"
maxReceivedMessageSize="4097152"
maxBufferPoolSize="4097152">
<readerQuotas
maxStringContentLength="4097152"
maxArrayLength="4097152"
maxBytesPerRead="4097152"
maxNameTableCharCount="4097152"
maxDepth="4097152"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service.Concrete.PublicService" behaviorConfiguration="ServiceBehavior">
<endpoint address="PublicService" binding="wsHttpBinding" name="PublicService" contract="Service.Abstract.IPublicService" bindingConfiguration="android"/>
<endpoint binding="mexHttpBinding" bindingConfiguration="" name="mex" contract="IMetadataExchange"/>
</service>
在过去的几个小时里,我一直在用头撞墙,并通过无数次谷歌搜索,我完全不知道下一步该做什么。如果有人知道我做错了什么,任何建议将不胜感激。
【问题讨论】:
-
最好避免使用 KSOAP2 以获得与 android 的最大可比性。 Google android 官方不支持 SOAP。 KSOAP2 可能有效,但它不是商业 Android 应用程序的正确解决方案。