JSON을 통해 통신하는 WCF 웹 서비스를 만들고 있습니다. 서비스가 작동하고 있고 도움말 페이지를 설정하려고하는데 서비스를 사용할 개발자가 작업 할 문서가있을 수 있습니다.WCF 도움말 페이지에서 JSON에서 XML로 응답을 변경합니다.
제가 실행중인 문제는 도움말 페이지를 열어서 실행했을 때 내 서비스에서 전송 된 모든 응답이 JSON에서 XML로 변경된 것입니다.
나는 이것이 아주 새로운 것을 처음으로 인정할 것이다. 내 서비스를 구조화 한 방법에 근본적인 결함이있을 수도 있고, web.config에 놓친 플래그처럼 간단 할 수도 있습니다. 지금은 정말 실망 스럽습니다.
<standardEndpoint name="serviceEndpoint" helpEnabled="true" automaticFormatSelectionEnabled="true">
가 빈 문자열하려면
내가 무엇을 발견, 기본적으로 그냥 시행 착오와 벽에 내 머리를 때리고을 통해, 내가의 Web.config에 다음 줄의 이름 속성을 변경하는 경우였다 :
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true">
도움말 페이지가 마술처럼 나타나지만 내 서비스가 JSON 대신 XML을 쓰고 있습니다.
나는 이보다 더 많은 것을 공유하는 것보다는 과다 공유하는 것이 더 낫다고 생각한다. 그래서 여기에 설정의 관련 비트가 있다고 생각한다. 모노 톤 코드에 대해 사과드립니다. 방법을 알아 내면 더 읽기 쉽도록 편집 할 수 있습니다.
서비스 인터페이스 :
[OperationContract]
[Description("DESCRIPTIONATION HAPPENS")]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "GetYears")]
GetYearsReply GetYears();
...
서비스 구현 :
[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#" %>
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 미디어 유형을 지정하는 'Accept' 헤더가 있는지 확인할 수 있습니까? 'autoFormatSelectionEnabled'를 true로 설정하면, 작업의'ResponseFormat' 속성을 통해 Accept 헤더를 선택할 것입니다. – carlosfigueira
수락 : text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8 – zeonic
그럼 분명히 ...하지만 왜? o.O – zeonic