English 中文(简体)
A. 扶持妇联 JSON对XML的反应
原标题:Enabling WCF Help page changes response from JSON to XML
  • 时间:2012-01-12 22:13:32
  •  标签:
  • wcf

Im通过JSON进行网络宣传。 我把这一服务引向一个工作点,一米试图设立帮助页,这样,消费服务的开发商可以有某些文件工作。

我所谈到的问题是,当我获得帮助时,我的服务提供的所有答复都从JSON改为XML。

我首先要承认,我对此非常新。 在我如何安排我的工作方面可能存在一些根本性的缺陷,或者它可能像我在网络中错过的一个旗帜一样简单。 此时此刻,我确实在遭受损失。

我发现,通过基本上公正的审判和错误,以及把我头顶在墙上,如果我改变网上以下线的名称的话。

<standardEndpoint name="serviceEndpoint" helpEnabled="true" automaticFormatSelectionEnabled="true">

空洞:

<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true">

帮助页大体显示,但我的服务现在却挤出XML,而不是JSON。

我认为,如果是这样具体的事情,则可能比对分配不足更有利,因此,我认为,这是既定办法的相关内容。 我对单州法典表示歉意,如果我这样说的话,我就可以认为它更容易读。

www.un.org/Depts/DGACM/index_spanish.htm

[OperationContract]
[Description("DESCRIPTIONATION HAPPENS")]
[WebInvoke(Method = "GET",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json,
                UriTemplate = "GetYears")]
GetYearsReply GetYears();
...

Service Implementation:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MPG : IMPG
{
    public GetYearsReply GetYears()
    {
        GetYearsReply reply = new GetYearsReply();
        reply.YearList = generateYears();
        return reply;
    }
...

Global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="MPG_Service.Global" Language="C#" %>

<>strong>Global.asax.cs:

namespace MPG_Service
{
    public class Global : System.Web.HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();

        }

        private void RegisterRoutes()
        {
            RouteTable.Routes.Add(new ServiceRoute("garage", new WebServiceHostFactory(), typeof(MPG)));
        }
    }
}

<Web.config:

<?xml version="1.0"?>
<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </modules>
    </system.webServer>

    <system.serviceModel>

        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

        <standardEndpoints>
            <webHttpEndpoint>
                <!-- 
                    Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
                    via the attributes on the <standardEndpoint> element below
                -->
                <standardEndpoint name="serviceEndpoint" helpEnabled="true" automaticFormatSelectionEnabled="true">
                    <!--<security mode="Transport">
                        <transport clientCredentialType="None"/>
                    </security>-->
                </standardEndpoint>
            </webHttpEndpoint>
        </standardEndpoints>  

    </system.serviceModel>

</configuration>

如果任何人都对这种行为发生的原因有任何了解,或者在我的法典中,任何其它重大改观者都热爱任何投入。

最佳回答

你的客户说,它接受XML(application/xml),这样,WCF正在返回。 这符合自动格式规则(见http://msdn.microsoft.com/en-us/library/ee476510.aspx” rel=“nofollow”http://msdn.microsoft.com/en-us/library/ee476510.aspxautoFormatSelectionEnabled。

问题回答

暂无回答




相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签