콘텐츠 유형 text / xml; charset = utf-8은 서비스에서 지원되지 않습니다.
WCF 서비스에 문제가 있습니다. 콘솔 애플리케이션이 있고 app.config를 사용하지 않고 서비스를 사용해야하므로 코드로 엔드 포인트 등을 설정해야했습니다. svc에 대한 서비스 참조가 있지만 app.config를 사용할 수 없습니다. 내 코드는 다음과 같습니다.
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8731/WcfServicio/MiServicio");
MiServicioClient svc = new MiServicioClient(binding, address);
object ob = svc.PaisesObtener();
마지막 줄 svc.PaisesObtener()
에 오류가 발생합니다.
Content Type text/xml; charset=utf-8 was not supported by service
http://localhost:8731/WcfServicio/MiServicio. The client and service bindings may be mismatched.
첫 번째 Google 히트작 :
이는 일반적으로 서비스의 메시지 버전이 SOAP 1.2 (application / soap + xml을 예상 함)를 사용하고 클라이언트의 버전이 SOAP 1.1 (텍스트 / xml을 전송 함)을 사용하는 클라이언트 / 서버 바인딩의 불일치입니다. WSHttpBinding은 SOAP 1.2를 사용하고 BasicHttpBinding은 SOAP 1.1을 사용합니다.
일반적으로 한쪽에는 wsHttpBinding이고 다른쪽에는 basicHttpBinding 인 것으로 보입니다.
바인딩 관련 코드도 확인하는 것을 잊지 마십시오. 따라서 다음과 같이 썼다면
BasicHttpBinding binding = new BasicHttpBinding();
모든 app.config
파일에
<endpoint address="..."
binding="basicHttpBinding" ...
아니
<endpoint address="..."
binding="wsHttpBinding" ...
그 쯤.
나는 오늘이 행동을 보았다.
<service name="A.B.C.D" behaviorConfiguration="returnFaults">
<endpoint contract="A.B.C.ID" binding="basicHttpBinding" address=""/>
</service>
web.config에서 누락되었습니다. service.svc
파일이 있었다 및 제공되었다. 문제가 바인딩 구성 자체가 아니라는 것을 깨닫는 데 시간이 걸렸습니다.
오늘 VS2010과 svcutil을 사용하여 WCF 서비스 프록시를 만들려고 할 때이 문제를 보았습니다.
내가하는 모든 것은 basicHttpBinding
(그래서 문제가되지 않습니다 wsHttpBinding
).
처음으로 MSDN은 실제로 다음 링크에서 솔루션을 제공 했습니다. 방법 : 구성 파일을 사용하여 서비스에 대한 메타 데이터 게시 . 변경해야하는 줄은 내 서비스 app.config 파일 내의 MEX 서비스 동작 요소 내부의 동작 요소 안에있었습니다. 나는 그것을
<serviceMetadata httpGetEnabled="true"/>
to
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
마법처럼 오류가 사라지고 서비스 프록시를 만들 수있었습니다. 구성 파일 대신 코드를 사용하기위한 해당 MSDN 항목 ( 방법 : 코드를 사용하여 서비스에 대한 메타 데이터 게시)이 있습니다.
(물론, Policy15-어떻게 그걸 간과 할 수 있었을까요 ???)
또 하나의 "문제": 내 서비스는 각각 다른 계약을 지원하는 3 개의 다른 엔드 포인트를 노출해야합니다. 빌드해야하는 각 프록시에 대해 다른 2 개의 엔드 포인트를 주석 처리해야했습니다. 그렇지 않으면 svcutil이 기본 URL 주소를 확인할 수 없다고 불평합니다.
Channel Factory를 사용할 때 비슷한 문제에 직면했습니다. 실제로 끝점에 지정된 잘못된 계약 때문이었습니다.
검색하여 여기에 도착하는 모든 사람 :
콘텐츠 유형 'application / json; charset = utf-8 '은 예상 유형'text / xml '이 아닙니다. charset = utf-8
또는 해당 오류의 일부 하위 집합 :
제 경우에는 적절한 속성없이 서비스를 빌드하고 실행하여 비슷한 오류가 발생했습니다. 클라이언트 응용 프로그램에서 서비스 참조를 업데이트하려고 할 때이 오류 메시지가 나타납니다. 사용자 정의 클래스에 올바르게 적용 [DataContract]
하고 [DataMember]
특성을 지정 하면 해결되었습니다 .
이는 서비스가 설정되어 작동 중이고 편집 한 후 중단 된 경우에 적용 할 수 있습니다.
최근에도 같은 문제에 직면했습니다. 몇 시간 동안 고생 한 끝에 마침내 해결책이 나왔습니다.
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
to your SVC markup file. e.g.
ServiceHost Language="C#" Debug="true" Service="QuiznetOnline.Web.UI.WebServices.LogService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
이제 응용 프로그램을 성공적으로 컴파일하고 실행할 수 있습니다.
다시 말하지만 네임 스페이스, svc 이름 및 계약이 web.config 파일에 올바르게 지정되어야 함을 강조합니다.
<service name="NAMESPACE.SvcFileName">
<endpoint contract="NAMESPACE.IContractName" />
</service>
예:
<service name="MyNameSpace.FileService">
<endpoint contract="MyNameSpace.IFileService" />
</service>
(Unrelevant tags ommited in these samples)
In my case, I had to specify messageEncoding to Mtom in app.config of the client application like that:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IntegrationServiceSoap" messageEncoding="Mtom"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:29495/IntegrationService.asmx"
binding="basicHttpBinding" bindingConfiguration="IntegrationServiceSoap"
contract="IntegrationService.IntegrationServiceSoap" name="IntegrationServiceSoap" />
</client>
</system.serviceModel>
</configuration>
Both my client and server use basicHttpBinding. I hope this helps the others :)
'Nice programing' 카테고리의 다른 글
CodeIgniter-한 행만 반환합니까? (0) | 2020.10.28 |
---|---|
SQL에서 난수로 열을 어떻게 채울 수 있습니까? (0) | 2020.10.28 |
C ++의 클래스 선언 내에서 const 멤버 초기화 (0) | 2020.10.28 |
DOM을 사용하여 기존 SVG에 SVG 요소 추가 (0) | 2020.10.28 |
스위프트 인라인 조건부? (0) | 2020.10.28 |