The content type application/json of the response message does not match the content type of the binding (application/soap+xml;

 Communication Foundation (WCF) 来创建异步 JavaScript XML (AJAX) 服务,该服务返回 JavaScript 对象表示法 (JSON) XML 数据。可以从 Web 浏览器客户端使用 JavaScript 代码来访问 AJAX 服务。此示例是基于 基本 AJAX 服务示例生成的。

 

You can see that there's nothing in there that says anything about JSON support, yet we can configure this service to return JSON over HTTP instead of SOAP.  .NET 3.5 introduces JSON serialization support for services without having to decorate your code with any special attributes, you just configure an endpoint to use the webHttpBinding, and add an endpoint behavior that enables web scripting.

  <system.serviceModel>

    <behaviors>

      <endpointBehaviors>

        <behavior name="AjaxBehavior">

          <enableWebScript />

        </behavior>

      </endpointBehaviors>

    </behaviors>

    <services>

      <service name="Service">

        <endpoint

          address=""

          binding="webHttpBinding"

          contract="IService"

          behaviorConfiguration="AjaxBehavior" />       

      </service>

    </services>

  </system.serviceModel>

Very cool, now our service is exposed and returns JSON over HTTP instead of XML over HTTP!  You can now go to your service endpoint and append "/js" to the querystring to see the JSON proxy that is generated.  For instance, the endpoint URL on my machine is:

http://localhost:49455/WCFServices/Service.svc/js

To call the service, ASP.NET 3.5's built-in AJAX support makes referencing the JavaScript proxy very simple.

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts.js" />
        </Scripts>
        <Services>
            <asp:ServiceReference Path="~/Service.svc" />
        </Services>
    </asp:ScriptManager>

In this example, I am using the ScriptManager control in ASP.NET and pointing to our Service.svc host file.  Thanks to the JavaScript Intellisense features in Visual Studio 2008, I get Intellisense completion so that I can figure out how to reference the proxy correctly.

 

 

 

Problem : Manual addressing is enabled on this factory, so all messages sent must be pre-addressed. 

Reslove: client.Endpoint.Behaviors.Add(new System.ServiceModel.Description.WebHttpBehavior());

 

 

总体 解决:

 

 

client invoke the function.

 

这个问题的主要原因是因为 server(application/json) , client(application/xml, soap) 编码方式不一样,所以 server 返回来的消息client 无法解析. 改变 client binding,

 

 

 

The SOAPAction header is actually pretty common - I have a feeling it may even be required for SOAP 1.2, if not expected for SOAP 1.1 (asmx) it;s certainly pervasive in WCF when using the wsHttpBinding which is SOAP 1.2 (the basicHttpBinding is SOAP 1.1). Not strictly sharepoint related, but important to raise, since the services that don't require it are possibly not SOAP compliant. I say possibly because I'm not an authority on the subject and I don't know the spec for sure, I just know I've been caught out by this a lot when learning WCF.

 

 

In my ongoing quest to produce the simplest table possible summarizing the key differences between the various Windows Communication Foundation (WCF) built-in bindings, I came up with the following:

 

Binding Class Name

Transport

Message Encoding

Message Version

Security Mode

RM

Tx Flow*

BasicHttpBinding

HTTP

Text

SOAP 1.1

None

X

X

WSHttpBinding

HTTP

Text

SOAP 1.2

WS-A 1.0

Message

Disabled

WS-AT

WSDualHttpBinding

HTTP

Text

SOAP 1.2

WS-A 1.0

Message

Enabled

WS-AT

WSFederationHttpBinding

HTTP

Text

SOAP 1.2

WS-A 1.0

Message

Disabled

WS-AT

NetTcpBinding

TCP

Binary

SOAP 1.2

Transport

Disabled

OleTx

NetPeerTcpBinding

P2P

Binary

SOAP 1.2

Transport

X

X

NetNamedPipesBinding

Named Pipes

Binary

SOAP 1.2

Transport

X

OleTx

NetMsmqBinding

MSMQ

Binary

SOAP 1.2

Message

X

X

MsmqIntegrationBinding

MSMQ

X**

X

Transport

X

X

CustomBinding

You decide

You decide

You decide

You decide

You decide

You decide

 

2. Content-Type

SOAP 1.1 HTTP/SOAP 消息的媒体类型为“text/xml”,其编码处理是在 RFC2376 中定义的。而 SOAP 1.2 HTTP/SOAP 消息的媒体类型为“application/soap+xml”,其编码处理是在 RFC3023 中定义的。这些 RFC 规范定义了下列行为:

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值