应用SSL后,无法从Android应用程序访问WCF服务。 415无法处理消息,因为内容类型'application / json'不是预期类型'text / xml;字符集= UTF-8' [英] Unable to access WCF services from android app after applying SSL. 415 Cannot process the message because the content type 'application/json' was not the expected type 'text/xml; charset=utf-8'

查看:74
本文介绍了应用SSL后,无法从Android应用程序访问WCF服务。 415无法处理消息,因为内容类型'application / json'不是预期类型'text / xml;字符集= UTF-8'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务Web.config: -

----------------------------

Service Web.config:-
----------------------------

<system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="jsonpSsl" crossDomainScriptAccessEnabled="true">
                    <security mode="Transport">
                    </security>
                </binding>
            </webHttpBinding>
        </bindings>
        <services>
            <service name="Paytonic.API.UserService" behaviorConfiguration="ServiceBehavior">
                <endpoint address="" binding="basicHttpBinding" contract="Paytonic.API.IUserService" />
                <endpoint address="json" binding="webHttpBinding" contract="Paytonic.API.IUserService" behaviorConfiguration="EndPointBehavior" bindingConfiguration="jsonpSsl"/>
                <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="EndPointBehavior">
                    <webHttp helpEnabled="true" defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"
                      automaticFormatSelectionEnabled="true" />
                    <enableWebScript/>
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <useRequestHeadersForMetadataAddress>
                        <defaultPorts>
                            <add scheme="https" port="443" />
                        </defaultPorts>
                    </useRequestHeadersForMetadataAddress>
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <standardEndpoints>
            <webScriptEndpoint>
                <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
            </webScriptEndpoint>
            <webHttpEndpoint>
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" defaultOutgoingResponseFormat="Json">
                </standardEndpoint>
            </webHttpEndpoint>
        </standardEndpoints>
        <protocolMapping>
            <!--<add binding="webHttpBinding" scheme="https" bindingConfiguration="jsonpSsl" />-->
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>





WCF服务: -

--------- --------





WCF Service:-
-----------------

[ServiceContract]
public interface IUserService
{
   [OperationContract]
   GetUserDetailsResponse GetUserDetails(GetUserDetailsRequest request);
}
    [DataContract]
    public class GetUserDetailsRequest : Request
    {
        [DataMember]
        public long UserID { get; set; }

    }

    [DataContract]
    public class GetUserDetailsResponse : Response
    {
        [DataMember]
        public UserEntity User { get; set; }
    }

推荐答案

看起来你的android端代码希望数据格式化为带有UTF的text / xml -8编码,但您的服务使用json作为所有接口函数的默认格式(服务webconfig包含> defaultOutgoingResponseFormat =Json<)。



您可以更改默认响应格式为text / xml或(如果不是所有函数都应使用相同的输出格式)使用函数属性(请参阅VS文档)。



如果web服务也被其他进程使用,这样你就无法改变它的输出格式,你可以为你的Android应用程序创建第二个web服务或者更改预期格式为json(如果可能)。
Looks like your android side code expects the data formatted as text/xml with UTF-8 encoding but your service uses json as default format for all interface functions (service webconfig contains >defaultOutgoingResponseFormat="Json"<).

You may either change that default response format to "text/xml" or (if not all functions should use same output format) use function attributes (see VS documentation).

If the webservice is consumed also by other processes so that you can't change it's output formats you may either create a second web service for your android app or change the expected format to json (if possible).


这篇关于应用SSL后,无法从Android应用程序访问WCF服务。 415无法处理消息,因为内容类型'application / json'不是预期类型'text / xml;字符集= UTF-8'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆