2012-03-05 4 views
0

WCF를 사용하려고하는데 문제가 있습니다 (그 중 일부는 며칠 동안 머리카락을 뽑아 냈습니다). 서비스를 사용하여 다른 RESTful 서비스를 호출 할 수 있습니다.WCF 서비스 - json을 사용하여 나머지에 액세스하는 클라이언트를 호출하면 올바른 콘텐츠 유형이 제공되지 않습니다.

그러나이를 통해 추적 할 때 올바른 json 콘텐츠 형식을 메시지에 넣지 못할 수 있습니다. 클라이언트에서 호출

예 (이 코드를 호출하는 WCF 서비스 내에)

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior()] 
public partial class MyRestServiceClient : System.ServiceModel.ClientBase<IMyRestService>, IMyRestService 
{ 
    [WebInvoke(Method = "POST", UriTemplate = "/MyService/ReferenceTypes.json", RequestFormat = WebMessageFormat.Json)] 
    public MyServiceLists GetReferenceTypes() 
    { 
     try 
     { 
      return base.Channel.GetReferenceTypes(); 
     } 
     catch (Exception e) 
     { 
      throw e; //throws exception here - method not allowed 
     } 
    } 
} 

대신은 전화 대신 응용 프로그램/XML을 배치 응용 프로그램/JSON의 콘텐츠 형식을 넣어. 이것은 호출을 수행하는 WCF 서비스에 배치 된 활동 추적에서 해결되었습니다. 의 예를 들어 활동 로그에서 정보를 "메시지가 전송"나는 클라이언트에 대한으로 WebHttpBinding을 사용했다

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> 
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> 
<EventID>262164</EventID> 
<Type>3</Type> 
<SubType Name="Information">0</SubType> 
<Level>8</Level> 
<TimeCreated SystemTime="2012-03-05T12:26:52.8913972Z" /> 
<Source Name="System.ServiceModel" /> 
<Correlation ActivityID="{7759c13c-972d-46a2-8048-2dcaf1c066bf}" /> 
<Execution ProcessName="aspnet_wp" ProcessID="2408" ThreadID="11" /> 
<Channel /> 
<Computer>Z1020734</Computer> 
</System> 
<ApplicationData> 
<TraceData> 
<DataItem> 
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"> 
<TraceIdentifier>http://msdn.microsoft.com/en-GB/library/System.ServiceModel.Channels.MessageSent.aspx</TraceIdentifier> 
<Description>Sent a message over a channel.</Description> 
<AppDomain>/LM/w3svc/1/ROOT/My.Services-2-129754240054859056</AppDomain> 
<Source>System.ServiceModel.Channels.HttpOutput+WebRequestHttpOutput/18905726</Source> 
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"> 
<MessageProperties> 
**<Encoder>application/xml; charset=utf-8</Encoder>** 
<AllowOutputBatching>False</AllowOutputBatching> 
<Via>http://mymachine/My.services.stub.REST/</Via> 
</MessageProperties> 
<MessageHeaders></MessageHeaders> 
</ExtendedData> 
</TraceRecord> 
</DataItem> 
</TraceData> 
</ApplicationData> 
</E2ETraceEvent> 

, 그럼 내가 또한 JSON을 강제로 사용자 정의 웹 콘텐츠 형식 매퍼와 사용자 정의 바인딩 상당을 시도했습니다 콘텐츠 유형을 사용할 수 없습니다.

클라이언트 엔드 포인트가 동일한 시스템에서 Restful 서비스 (Rest 40 템플리트 사용)를 가리키고 있습니다.

<?xml version="1.0"?> 
<configuration> 
    <connectionStrings> 
    </connectionStrings> 
    <appSettings> 
    </appSettings> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <system.serviceModel> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service name="My.Services.MyService" behaviorConfiguration="My.Services.MyServiceBehavior" > 
     <endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding_IMyService" contract="My.Common.ServiceContracts.IMyService"/> 
     </service> 
     <service name="My.Services.SomeOtherService" behaviorConfiguration="My.Services.SomeOtherBehavior" > 
     <endpoint address="" binding="customBinding" bindingConfiguration="customBinding_ISomeOtherService" contract="My.Common.ServiceContracts.ISomeOtherService"/> 
     </service> 
    </services> 
    <bindings> 
     <webHttpBinding> 
     <binding name="webHttpCustomBinding"> 
      <security mode="TransportCredentialOnly"> 
      <transport proxyCredentialType="None" clientCredentialType="Windows"> 
      </transport> 
      </security> 
     </binding> 
     </webHttpBinding> 

     <customBinding> 
     <binding name ="CustomBinding_IIMyRestService"> 
      <webMessageEncoding webContentTypeMapperType="My.Common.ServiceModel.JsonContentTypeMapper, My.Common" ></webMessageEncoding> 
      <httpTransport authenticationScheme="Negotiate" ></httpTransport> 
     </binding> 
     <binding name="CustomBinding_IMyService"> 
      <textMessageEncoding messageVersion="Soap12" /> 
      <httpTransport maxBufferPoolSize="1000000" maxReceivedMessageSize="1000000" 
      authenticationScheme="Negotiate" maxBufferSize="1000000" /> 
     </binding> 
     <binding name="customBinding_ISomeOtherService"> 
      <textMessageEncoding messageVersion="Soap12" /> 
      <httpTransport /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://MyMachine/My.services.stub.REST/" binding="customBinding" bindingConfiguration="CustomBinding_IMyRestService" name="RestService" contract="My.Common.ServiceContracts.IIMyRestService" behaviorConfiguration="webhttp"/> 
</client> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="webhttp"> 
     </behavior> 
</endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="My.Services.MyServiceBehavior"> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     <behavior name="My.Services.SomeOtherServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <system.net> 
    <defaultProxy useDefaultCredentials="true"/> 
    </system.net> 
<system.diagnostics> 
    <trace autoflush="true"/> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
     <listeners> 
      <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\my.Services.svclog"/> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
</configuration> 

참고 : 는 나머지 엔드 포인트를 호출하려고하는 WCF 서비스의 Web.config의 내용은 아래 참조 내가 동일한 기능 및 구성에 작성한 콘솔 응용 프로그램이 제대로 작동합니까, 그리고 올바른을 제공합니다 컨텐츠 타입.

도움을 주시면 감사하겠습니다.

답변

2

아직 해결되지 않았는지 확실하지 않지만 같은 문제가 발생했습니다.
기존 서비스 호출 내에서 서비스를 호출 할 때 새 호출을 새 OperationContextScope에 랩핑해야합니다.

현재 세부 사항을 볼 수 있습니다 WCF Rest Client sending incorrect content-type

+0

덕분 정보를 원하시면 - 나는 결국이 해결 거지, 우리의 프록시 방식으로 얻는 한 방법까지했다. 우리는 필요한 자격 증명을 지정한 사용자 지정 프록시 (올바른 기억이있는 경우)를 사용했습니다. 다행히도 우리 프로덕션 시스템에서는 문제가되지 않았습니다. – williamfalconeruk

관련 문제