C# wcf wshttpbinding与用户名和密码验证程序协议异常+;XmlException
我有一个wcf服务,在服务器端有此配置:C# wcf wshttpbinding与用户名和密码验证程序协议异常+;XmlException,c#,xml,wcf,C#,Xml,Wcf,我有一个wcf服务,在服务器端有此配置: WSHttpBinding wshttp = new WSHttpBinding(SecurityMode.Message); wshttp.ReceiveTimeout = new TimeSpan(0, 30, 0); wshttp.MaxBufferPoolSize = 2147483647; wshttp.MaxReceivedMessageSize = 2147483647; wshttp.ReaderQuotas.MaxArrayLengt
WSHttpBinding wshttp = new WSHttpBinding(SecurityMode.Message);
wshttp.ReceiveTimeout = new TimeSpan(0, 30, 0);
wshttp.MaxBufferPoolSize = 2147483647;
wshttp.MaxReceivedMessageSize = 2147483647;
wshttp.ReaderQuotas.MaxArrayLength = 2147483647;
wshttp.ReaderQuotas.MaxBytesPerRead = 2147483647;
wshttp.ReaderQuotas.MaxDepth = 2147483647;
wshttp.ReaderQuotas.MaxNameTableCharCount = 2147483647;
wshttp.ReaderQuotas.MaxStringContentLength = 2147483647;
wshttp.Security.Message.AlgorithmSuite =
System.ServiceModel.Security.SecurityAlgorithmSuite.Basic256Sha256Rsa15;
wshttp.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
CustomBinding cb = new CustomBinding(wshttp);
var clockSkew = new TimeSpan(2, 0, 0);
SymmetricSecurityBindingElement security =
cb.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = clockSkew;
security.LocalServiceSettings.MaxClockSkew = clockSkew;
// Get the
// System.ServiceModel.Security.Tokens
// .SecureConversationSecurityTokenParameters
SecureConversationSecurityTokenParameters secureTokenParams =
(SecureConversationSecurityTokenParameters)
security.ProtectionTokenParameters;
// From the collection, get the bootstrap element.
SecurityBindingElement bootstrap =
secureTokenParams.BootstrapSecurityBindingElement;
// Set the MaxClockSkew on the bootstrap element.
bootstrap.LocalClientSettings.MaxClockSkew = clockSkew;
bootstrap.LocalServiceSettings.MaxClockSkew = clockSkew;
EndpointAddress ea =
new EndpointAddress(
new Uri("http://localhost:80/MyService"),
System.ServiceModel.EndpointIdentity.CreateDnsIdentity(
"MyService Certeficate"));
isarService.AddServiceEndpoint(
typeof(ServiceLayer.IService),
cb,
new Uri("http://localhost:80/MyService")).Address = ea;
isarService.Open();
WSHttpBinding wshttp=newwshttpbinding(SecurityMode.Message);
wshttp.ReceiveTimeout=新的时间跨度(0,30,0);
wshttp.MaxBufferPoolSize=2147483647;
wshttp.MaxReceivedMessageSize=2147483647;
wshttp.ReaderQuotas.MaxArrayLength=2147483647;
wshttp.ReaderQuotas.MaxBytesPerRead=2147483647;
wshttp.ReaderQuotas.MaxDepth=2147483647;
wshttp.ReaderQuotas.MaxNameTableCharCount=2147483647;
wshttp.ReaderQuotas.MaxStringContentLength=2147483647;
wshttp.Security.Message.AlgorithmSuite=
System.ServiceModel.Security.SecurityAlgorithmSuite.Basic256SHA25;
wshttp.Security.Message.ClientCredentialType=MessageCredentialType.UserName;
CustomBinding cb=新的CustomBinding(wshttp);
var clockSkew=新的时间跨度(2,0,0);
SymmetricSecurity绑定元素安全=
cb.Elements.Find();
security.LocalClientSettings.MaxClockSkew=clockSkew;
security.LocalServiceSettings.MaxClockSkew=clockSkew;
//得到
//System.ServiceModel.Security.Tokens
//.SecureConversationSecurityTokenParameters
SecureConversationSecurityTokenParameters secureTokenParams=
(SecureConversationSecurityTokenParameters)
security.protectiontoken参数;
//从集合中获取引导元素。
SecurityBindingElement引导=
secureTokenParams.BootstrapSecurityBindingElement;
//在引导元素上设置MaxClockSkew。
bootstrap.LocalClientSettings.MaxClockSkew=clockSkew;
bootstrap.LocalServiceSettings.MaxClockSkew=clockSkew;
端点地址ea=
新端点地址(
新Uri(“http://localhost:80/MyService"),
System.ServiceModel.EndpointIdentity.CreateDnsIdentity(
“我的服务证书”);
isarService.AddServiceEndpoint(
类型(ServiceLayer.IService),
cb,
新Uri(“http://localhost:80/MyService)地址=ea;
isarService.Open();
配置的一半在应用程序文件中,如下所示:
<system.serviceModel>
<bindings />
<client />
<services>
<service behaviorConfiguration="ServiceBehavior" name="SL.Service">
<endpoint address="mex" binding="
mexHttpBinding"
bindingConfiguration=""
name="MexHttpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/MyService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling maxConcurrentCalls="100"
maxConcurrentInstances="100" />
<serviceCredentials>
<clientCertificate>
<authentication customCertificateValidatorType=""
certificateValidationMode="ChainTrust" />
</clientCertificate>
<serviceCertificate findValue="MyService Certeficate"
storeLocation="CurrentUser"
storeName="Root" x509FindType="FindByIssuerName" />
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="ServiceLayer.CUAPValidator,ServiceLayer" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我记录我的客户端错误,他们向我发送日志文件以修复他们的应用程序。应用程序适用于我的许多客户端,但其中一些客户端存在此错误:
System.ServiceModel.ProtocolException->从网络接收的XML有问题。有关详细信息,请参阅内部异常
System.Xml.xmleexception->根级别的数据无效。第1行,位置1
我不知道99客户端何时能很好地使用此配置,为什么其中3个会出现此问题
问题:
请帮助我用最简单的方法解决这个问题
信息:
我使用windows服务托管我的服务
编辑1:
我在客户端使用svc日志精确记录错误。然后我读到了错误,错误就是这样。在服务器端,我在日志中没有看到错误。我不知道什么是完全不同的,但似乎不同的是互联网连接,我的意思是代理服务器或vpn等
编辑2:
对于.net版本会发生这种情况吗??因为版本4有一些更新
编辑3:
看到这个错误了吗?它与其他可能的帮助相同
响应消息的内容类型text/html与绑定的内容类型不匹配(application/soap+xml;charset=utf-8)。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。响应的前1024个字节是:'
错误消息
A{
字体大小:粗体;字体大小:10pt;颜色:#005a80;字体系列:tahoma
}
A:悬停{
字体大小:粗体;字体大小:10pt;颜色:#0d3372;字体系列:tahoma
}
运输署{
字体大小:8pt;字体系列:tahoma
}
标题顺序{
右边框:#955319 1px实心;上边框:#955319 1px实心;左填充:8px;字体重量:粗体;字体大小:12pt;垂直对齐:中间;左边框:#955319 0px实心;颜色:#955319;下边框:#955319 1px实心;字体系列:塔荷马;高度:35px;背景色:d2b87a;文本对齐:左
}
TD.titleBorder_x{
右边框:#955319 0px实心;上边框:#955319 1px实心;左填充:8px;字体重量:粗体;字体大小:12pt;垂直对齐:中间;左边框:#955319 1px实心;颜色:#978c79;下边框:#955319 1px实心;字体系列:塔荷马;高度:35px;BACKGR’
和内部错误:
远程服务器返回错误:(500)内部服务器错误。这些客户端上有什么不同?另外,您是否尝试启用wcf跟踪并使用SvcTraceViewer.exe查看它?您的客户端在工作和不工作的PC上的配置是否相似?是的,每件事情都相似,但只有我的office合作伙伴有这样的网络ip连接:\myservice但对于其他城市的其他客户端i have-like\myservice