开发者

Making a WCF service Android compatible

I have a WCF service that is hosted on a remote server using IIS. I want to make this service android compatible so I can consume the service on an android client. The problem I'm having is that I'm trying to use ksoap2 to connect to the service but it's giving me a 400 error every time I try to call the method. I've used fiddler2 to try and see what the problem is and in addition to the 400 error, it's also sending back a content-length: 0 (don't know if that is the cause. Interesting fact, when I specify a content-length in the request on fiddler, it doesn't give me a 400 error but rather doesn't return a response at all) I've already tried changing the binding to a webHttpBinding instead of wsHttpBinding and adding a WebGet attribute above the method with a URITemplate, BodyStyle, etc. but no luck. Here's my code:

Service

    public class PublicService : IPublicService
{
    public Wallpaper[] GetWallpapers()
    {
        //return _wallpaperRepository.Items.ToArray();
        return new Wallpaper[]{ new Wallpaper()
                                    {
                                        Id = 10
                                    }};
    }
}

Interface

[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&开发者_开发百科gt;
        </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>

I've been beating my head against the wall for the past several hours and going through countless googling, I'm at a complete lost on what to do next. If anyone has any idea what I'm doing wrong, any advice would be greatly appreciated.


Use basicHttpBinding instead. You can try it with default configuration:

<endpoint address="PublicService" binding="basicHttpBinding" name="PublicService" contract="Service.Abstract.IPublicService" />

In your android service make sure that you are specifying correct SOAP action, correct namespaces and that SoapSerializationEnvelope is constructed for SOAP 1.1 and has dotNet flag set to true.

WsHttpBinding defaults to many advanced WS-* protocols. For example WS-Addressing which is set of well known SOAP headers. If you don't include them in your message WCF service will reject the request.

WebHttpBinding will also not solve the problem because that binding is used for REST services but you want to consume the service with ksoap = you need SOAP service.

Edit:

Another question on Stack overflow has nice example in the answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜