25 Kasım 2015 Çarşamba

WCF SecurityNegotiationException Hatası


"Unhandled Exception: System.ServiceModel.Security.SecurityNegotiationException: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. ---> System.ServiceModel.FaultException: The message with Action 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."

Hatasını aldığınızda Enpoint adresinde bazı security, mesaj ve Transport ayarlarından dolayı hata almaktasınız.Bu servisin yapısına göre değişkenlik gösterebilir.

Bir windows web servis için yaptığımız configurasyon örneği aşağıdaki gibidir

System.ServiceModel.WSHttpBinding binding = new System.ServiceModel.WSHttpBinding();



binding.MaxReceivedMessageSize = 2147483647;
binding.CloseTimeout = TimeSpan.MaxValue;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;

WSHttpSecurity _wsHttpSecurity = new WSHttpSecurity();
_wsHttpSecurity.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
_wsHttpSecurity.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
_wsHttpSecurity.Transport.Realm = "";

_wsHttpSecurity.Message.ClientCredentialType = MessageCredentialType.Windows;
_wsHttpSecurity.Message.NegotiateServiceCredential = true;
_wsHttpSecurity.Message.EstablishSecurityContext = true;

_wsHttpSecurity.Mode = SecurityMode.None;



binding.Security = _wsHttpSecurity;
.
EndpointAddress endpointAddress = new EndpointAddress("***/Retrieval.svc"); //Live


RetrievallWS.RetrievalClient retrievallWS = new RetrievallWS.RetrievalClient(binding, endpointAddress);


          

WCF Maximum Message Size Hatası

Bu hatayı her zaman değil servisten çekilen verinin boyutu 65536'ten büyük ise almaktasınız.

Hata metni aşağıdaki gibi ise;

"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

servisi şu şekilde değiştirmeniz gerekmektedir.


<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="****" allowCookies="true" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" />
</binding>
<binding name="****1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="*****"
binding="basicHttpBinding" bindingConfiguration="****"
contract="**.**" name="*****" />
<endpoint address="***" binding="basicHttpBinding"
bindingConfiguration="KodAYSWebServiceSoap1" contract="**.**"
name="WebServiceSoap1" />
</client>
</system.serviceModel>