CORS と WCF (REST ではなく SOAP) の統合に問題があります。js からリクエストを行うと、WCF トレース ログに「The body of the message cannot be read because it is empty」という例外が表示されます (論理的には、OPTION CORS リクエストに関連して)。
体:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing/">
<s:Header>
</s:Header>
<s:Body>
<GetInfo xmlns="http://tempuri.org/"></GetInfo>
</s:Body>
</s:Envelope>
JS リクエスト:
$.ajax({
type: "POST",
url: "http://localhost:8081/service_deploy/service1.svc/serviceSoap",
headers: { "SOAPAction": "http://tempuri.org/IService/GetInfo" },
data: body,
contentType: "text/xml",
timeout: 10000
});
CORS リクエスト:
OPTIONS http://localhost:8081/service_deploy/service1.svc/serviceSoap
HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Origin: http://localhost:49209
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type,soapaction
Pragma: no-cache
Cache-Control: no-cache
例外:
Type: System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Mes: There is a problem with the XML that was received from the network. See inner exception for more details.
Inner type: System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Inner mes: The body of the message cannot be read because it is empty.
スタックトレース:
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback) System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
CORS と WCF SOAP を統合したり、この低レベルの WCF 例外を処理するにはどうすればよいですか?