[英]Using SoapUI to test a WCF with Basic Authentication
我是Web服务的新手。 我想用用户名和密码验证编写一个简单的WCF。 使用SoapUI进行测试时,如果安全模式设置为无(无基本身份验证),则可以成功调用它。 一旦将安全模式设置为消息(使用基本身份验证),它就无法返回正确的结果。 两者都可以使用C#客户端成功调用。 我对StackOverflow应用了许多建议,但仍然无法获得正确的结果。
是否需要进行其他任何设置,例如配置证书? 我期待着您的帮助。
设置详细信息在下面列出。
当安全模式设置为message时,返回结果为
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
</s:Header>
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="zh-HK">An error occurred when verifying security for the message.</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
SoapUI日志:
DEBUG:尝试1执行请求DEBUG:发送请求:POST /ServiceHello.svc HTTP / 1.1 DEBUG:接收响应:HTTP / 1.1 500内部服务器错误DEBUG:可以无限期保持连接INFO:[WSHttpBinding_IServiceHello.HelloWorld的响应:请求1],以3ms(576字节)为单位
安全模式的结果=无
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/IServiceHello/HelloWorldResponse</a:Action>
</s:Header>
<s:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>Hello World</HelloWorldResult>
</HelloWorldResponse>
</s:Body>
</s:Envelope>
这是web.config
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="WCFTest.ServiceHello"
behaviorConfiguration="WCFTest_Behavior">
<endpoint
address=""
binding="wsHttpBinding"
contract="WCFTest.IServiceHello"
bindingConfiguration="WCFTest_Config">
</endpoint>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WCFTest_Config">
<security mode="None">
<!—The only difference between two web service is the security mode, which is set to message in the authentication version -->
<message clientCredentialType="UserName" negotiateServiceCredential="false"
establishSecurityContext="false" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WCFTest_Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None"/>
</clientCertificate>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCFTest.App_Code.Authentication.CustomValidator,App_Code/Authentication"/>
<serviceCertificate
findValue="myCertificate"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
在查看应用程序的配置时,我假设以下内容:a)您的WCF服务使用.NET Framework 4.5或更高版本。 b)该服务托管在启用了SSL安全性的IIS中。 c)您想使用WsHttpBinding。 d)认证是定制的。
因此,我给您以下建议:
IIS发布:
a)SSL安全性:启用“需要SSL和客户端证书”将其设置为“忽略”。 您如何在Web.config中配置它:
<clientCertificate>
<authentication certificateValidationMode = "None" />
</ clientCertificate>
b)身份验证:启用“匿名身份验证”并禁用其他身份验证。
Web.config文件:
<wsHttpBinding>
<binding name = "WCFTest_Config">
<security mode = "TransportWithMessageCredential">
<transport clientCredentialType = "None" proxyCredentialType = "None" realm = "" />
<message clientCredentialType = "UserName" />
</security>
</binding>
</wsHttpBinding>
并且
<protocolMapping>
<add binding = "wsHttpBinding" scheme = "https" />
</protocolMapping>
试试吧,祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.