[英]BasicHttpBinding equivalent CustomBinding using WCF Client and PHP WebService
I was running my Visual Studio 2008 Unit Test C# with a WebService PHP using WCF and I received the following error: 我正在使用WCF使用WebService PHP运行Visual Studio 2008单元测试C#,并且收到以下错误:
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. System.ServiceModel.Security.MessageSecurityException:使用客户端身份验证方案'Anonymous'的HTTP请求未经授权。 The authentication header received from the server was 'NTLM,Basic realm="(null)"'. 从服务器收到的身份验证标头是“ NTLM,Basic realm =“(null)””。 ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.. ---> System.Net.WebException:远程服务器返回错误:(401)未经授权。
I am using Windows XP SP3 machine, unit test VS 2008 and WCF for connect to PHP WebService. 我正在使用Windows XP SP3计算机,VS 2008和WCF进行单元测试以连接到PHP WebService。
I have no control about PHP WebService. 我无法控制PHP WebService。 I cannot modify it (neither configuration security). 我无法修改它(配置安全性都没有)。
Here is my config file for the client that use the webservice PHP: 这是使用Web服务PHP的客户端的配置文件:
<system.serviceModel>
<extensions>
<bindingElementExtensions>
<add name="customTextMessageEncoding"
type="COMPANY.IntegracionEasyVista.CustomTextEncoder.CustomTextMessageEncodingElement,COMPANY.IntegracionEasyVista.CustomTextEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744987c0853bf9e" />
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="ISO8859Binding">
<customTextMessageEncoding messageVersion="Soap11WSAddressing10"
encoding="ISO-8859-1" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://serverphp/webservice/SmoBridge.php"
binding="customBinding" bindingConfiguration="ISO8859Binding"
contract="ServiceEasyVista.WebServicePortType" name="EasyVistaSvcEndPoint" />
</client>
</system.serviceModel>
Really, I use C# code: 确实,我使用C#代码:
var endpointAddress = Config.AppSettings.Settings[EasyVistaSvcEndPointAddress].Value;
var endpoint = new System.ServiceModel.EndpointAddress(endpointAddress);
var endpointBinding = new System.ServiceModel.Channels.CustomBinding();
endpointBinding.Name = "ISO8859Binding";
var bindingElement = new IntegracionEasyVista.CustomTextEncoder.CustomTextMessageBindingElement();
bindingElement.Encoding = "ISO-8859-1";
bindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap11WSAddressing10; // "Soap11WSAddressing10"
endpointBinding.Elements.Add(bindingElement);
var transportBinding = new HttpTransportBindingElement();
endpointBinding.Elements.Add(transportBinding);
ConfigurarBinding(endpointBinding);
var svcClient = new WebServicePortTypeClient(endpointBinding, endpoint);
return svcClient;
Update: tests 更新:测试
I add this line: 我添加这一行:
transportBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate;
I get this error: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 我收到此错误:HTTP请求未经客户端身份验证方案“匿名”授权。 The authentication header received from the server was 'NTLM,Basic realm="(null)"' 从服务器收到的身份验证标头是“ NTLM,Basic realm =“(null)””
I add this line: 我添加这一行:
transportBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;
I get thiserror: 我收到此错误:
System.ServiceModel.CommunicationObjectFaultedException: El objeto de comunicación, System.ServiceModel.Channels.ServiceChannel, no se puede usar para la comunicación porque se encuentra en el estado Faulted. System.ServiceModel.CommunicationObjectFaultedException:通信对象,System.ServiceModel.Channels.ServiceChannel,没有在通信过程中使用任何错误的消息。
//Server stack trace: // en System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout) //服务器堆栈跟踪:// zh_cn System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan超时)
I add this line: 我添加这一行:
transportBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Ntlm;
I get thiserror: 我收到此错误:
/Exception = System.ServiceModel.CommunicationException: Versión de mensaje no reconocida. / Exception = System.ServiceModel.CommunicationException:取消侦听。
//Server stack trace: // en System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader) //服务器堆栈跟踪:// zh-CN System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader阅读器)
// en System.ServiceModel.Channels.StreamedMessage..ctor(XmlDictionaryReader reader, Int32 maxSizeOfHeaders, MessageVersion desiredVersion) // zh_cn System.ServiceModel.Channels.StreamedMessage..ctor(XmlDictionaryReader阅读器,Int32 maxSizeOfHeaders,MessageVersion requiredVersion)
// en System.ServiceModel.Channels.Message.CreateMessage(XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders, MessageVersion version) // zh_cn System.ServiceModel.Channels.Message.CreateMessage(XmlDictionaryReader信封阅读器,Int32 maxSizeOfHeaders,MessageVersion版本)
// en System.ServiceModel.Channels.Message.CreateMessage(XmlReader envelopeReader, Int32 maxSizeOfHeaders, MessageVersion version) // zh_cn System.ServiceModel.Channels.Message.CreateMessage(XmlReader信封阅读器,Int32 maxSizeOfHeaders,MessageVersion版本)
// en CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType) en E:\\TFS\\pro\\CustomTextEncoder\\CustomTextMessageEncoder.cs:línea 66 // // CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(Stream stream,Int32 maxSizeOfHeaders,String contentType)zh:E:\\ TFS \\ pro \\ CustomTextEncoder \\ CustomTextMessageEncoder.cs:línea66
// en System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders) // zh_cn System.ServiceModel.Channels.MessageEncoder.ReadMessage(流流,Int32 maxSizeOfHeaders)
// en CustomTextEncoder.CustomTextMessageEncoder.ReadMessage (ArraySegment`1 buffer, BufferManager bufferManager, String contentType) en E:\\TFS\\pro\\CustomTextEncoder\\CustomTextMessageEncoder.cs:línea 60 // zh_cn CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(ArraySegment`1缓冲区,BufferManager bufferManager,字符串contentType)zh:E:\\ TFS \\ pro \\ CustomTextEncoder \\ CustomTextMessageEncoder.cs:línea60
// en System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType) // zh_cn System.ServiceModel.Channels.MessageEncoder.ReadMessage(流流,BufferManager bufferManager,Int32 maxBufferSize,字符串contentType)
// en System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream) // zh_cn System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
I think, the following is right configuration (if were basichttpbinding) 我认为,以下是正确的配置(如果是basichttpbinding)
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
Web service of WCF in basichttpbinding might not be flexible enough. 基本httpbinding中的WCF的Web服务可能不够灵活。 CustomBinding as the name describes that it alllows users design their own web service binding. CustomBinding的名称描述了它允许用户设计自己的Web服务绑定。
I need use CustomBinding and SecurityMode (like basichttpbinding): WCF BasicHttpBinding equivalent CustomBinding 我需要使用CustomBinding和SecurityMode(如basichttpbinding):WCF BasicHttpBinding等效于CustomBinding
I need Security Mode: TransportCredentialOnly, Basic, HTTP transport and encoding="ISO-8859-1" 我需要安全模式:TransportCredentialOnly,基本,HTTP传输和编码=“ ISO-8859-1”
http://www.codemeit.com/security/wcf-basichttpbinding-equivalent-custombinding.html http://www.codemeit.com/security/wcf-basichttpbinding-equivalent-custombinding.html
http://social.msdn.microsoft.com/Forums/en/wcf/thread/6cefadf1-9939-4f3b-a502-2d79a30c7d3a http://social.msdn.microsoft.com/Forums/en/wcf/thread/6cefadf1-9939-4f3b-a502-2d79a30c7d3a
http://offroadcoder.com/2008/03/23/CallingYourNusoapPHPWebServiceFromWCF.aspx http://offroadcoder.com/2008/03/23/CallingYourNusoapPHPWebServiceFromWCF.aspx
http://msdn.microsoft.com/en-us/library/ms731092(v=VS.90).aspx http://msdn.microsoft.com/zh-CN/library/ms731092(v=VS.90).aspx
I try again using this configuration, and I get the error: 我使用此配置再次尝试,但出现错误:
svcPro.ClientCredentials.UserName.UserName = "MY USER";
svcPro.ClientCredentials.UserName.Password = "XXXX";
Config: 配置:
<customBinding>
<binding name="ISO8859Binding">
<customTextMessageEncoding messageVersion="Soap11WSAddressing10" encoding="ISO-8859-1" />
<!--<textMessageEncoding MessageVersion="Soap11" />-->
<!--<httpTransport />-->
<httpTransport authenticationScheme="Basic" />
</binding>
</customBinding>
The error (InnerException is null): 错误(InnerException为null):
Error: Unrecognized message version 错误:无法识别的消息版本
Tipo: System.ServiceModel.CommunicationException Mensaje: Versión de mensaje no reconocida. 提示:System.ServiceModel.CommunicationException Mensaje:无需重新确认。 StackTrace: Server stack trace: StackTrace:服务器堆栈跟踪:
en System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader) zh-cn System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader阅读器)
en System.ServiceModel.Channels.StreamedMessage..ctor(XmlDictionaryReader reader, Int32 maxSizeOfHeaders, MessageVersion desiredVersion) zh_cn System.ServiceModel.Channels.StreamedMessage..ctor(XmlDictionaryReader阅读器,Int32 maxSizeOfHeaders,MessageVersion requiredVersion)
en System.ServiceModel.Channels.Message.CreateMessage(XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders, MessageVersion version) zh_cn System.ServiceModel.Channels.Message.CreateMessage(XmlDictionaryReader信封阅读器,Int32 maxSizeOfHeaders,MessageVersion版本)
en System.ServiceModel.Channels.Message.CreateMessage(XmlReader envelopeReader, Int32 maxSizeOfHeaders, MessageVersion version) zh-cn System.ServiceModel.Channels.Message.CreateMessage(XmlReader信封阅读器,Int32 maxSizeOfHeaders,MessageVersion版本)
en Reale.IntegracionEasyVista.CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType) en E:\\IntegracionEasyVista\\CustomTextEncoder\\CustomTextMessageEncoder.cs:línea 66 zh-cn Reale.IntegracionEasyVista.CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(流,Int32 maxSizeOfHeaders,String contentType)zh-cn E:\\ IntegracionEasyVista \\ CustomTextEncoder \\ CustomTextMessageEncoder.cs:lnea 66
en System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders) en Reale.IntegracionEasyVista.CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType) en E:\\IntegracionEasyVista\\CustomTextEncoder\\CustomTextMessageEncoder.cs:línea 60 zh_cn System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream,Int32 maxSizeOfHeaders)zh_cn Reale.IntegracionEasyVista.CustomTextEncoder.CustomTextMessageEncoder.ReadMessage(ArraySegment`1 buffer,BufferManager bufferManager,String contentType)E:\\ IntegracionEasyVista \\ CustomTextEncoder \\ CustomTextMessage :莉娜60
en System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType) zh_cn System.ServiceModel.Channels.MessageEncoder.ReadMessage(流流,BufferManager bufferManager,Int32 maxBufferSize,字符串contentType)
en System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream) zh-cn System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
en System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException) zh-cn System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&requestException)
en System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) zh-cn System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan超时)
en System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) zh-cn System.ServiceModel.Channels.RequestChannel.Request(消息,TimeSpan超时)
en System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) zh-cn System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息,TimeSpan超时)
en System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) zh-cn System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan超时)
en System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) zh-cn System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins,Object [] outs)
en System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) zh-cn System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
en System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) zh-cn System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)
More info: part of WDSL of Service.php 更多信息:Service.php WDSL的一部分
<?xml version="1.0" encoding="ISO-8859-1" ?>
<definitions
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"
xmlns:tns="http://192.168.110.50/WebService" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://192.168.110.50/WebService">
<types>
<xsd:schema targetNamespace="http://192.168.110.50/WebService">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</xsd:schema>
</types>
Your PHP service requires authentication but your client doesn't send any. 您的PHP服务需要身份验证,但客户端不发送任何身份验证。 Change your custom binding to support authentication. 更改您的自定义绑定以支持身份验证。 You can set authentication in httpTransport element: 您可以在httpTransport元素中设置身份验证:
<httpTranposrt authenticationScheme="..." />
Use Basic or Negotiate. 使用基本或协商。 Basic will require you to provide client credentials when communicating with the service. Basic将要求您在与服务进行通信时提供客户端凭据 。 Negotiate will require that both service and client are in the same domain. 协商将要求服务和客户端都在同一个域中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.