询问者
2.0应用程序调用WCF服务时的用户名密码问题

问题
-
我的WCF服务,用的是基于证书的传输安全和消息安全机制,自定义用户名密码验证
我的客户端应用程序是framework2.0的,在visual studio里添加服务引用以后,自动生成了代码
但是提示如下消息:
未能找到元素“supportedRuntime”的架构信息
未能找到特性“version”的架构信息
未能找到元素“applicationSettings”的架构信息
未能找到元素“aaa.Properties.Settings”的架构信息
未能找到元素“setting”的架构信息
未能找到特性“name”的架构信息
未能找到特性“serializeAs”的架构信息
未能找到元素“value”的架构信息这并没有影响编译
调用远程方法的代码:
但是我的服务是有自定义用户名密码验证的,请问我应该在哪里填写用户名和密码?aaa.WSHttpBinding_IBasicData proxy = new aaa.WSHttpBinding_IBasicData(); term = proxy.GetCurrentTerm().TermNo.Substring(0, 4);
全部回复
-
WCFClient.ClientProxy.WCFServiceClient wcfServiceProxyHttp = new WCFClient.ClientProxy.WCFServiceClient("WSHttpBinding_IWCFService"); //通过代理调用SayHello服务 string sName = "Frank Xu Lei Transport Basic WSHttpBinding"; string sResult = string.Empty; //设置Windows用户和密码 wcfServiceProxy.ClientCredentials.UserName.UserName = "Administrator"; wcfServiceProxy.ClientCredentials.UserName.Password = "00000000"; Util.SetCertificatePolicy();//强制信任证书。重写验证服务端证书的方法。 sResult = wcfServiceProxyHttp.SayHello(sName); Console.WriteLine("Returned Result is {0}", sResult);
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
-
参考这个代码
WCFClient.ClientProxy.WCFServiceClient wcfServiceProxyHttp = new WCFClient.ClientProxy.WCFServiceClient("WSHttpBinding_IWCFService");
//通过代理调用SayHello服务
string sName = "Frank Xu Lei Transport Basic WSHttpBinding";
string sResult = string.Empty;
//设置Windows用户和密码
wcfServiceProxy.ClientCredentials.UserName.UserName = "Administrator";
wcfServiceProxy.ClientCredentials.UserName.Password = "00000000";
Util.SetCertificatePolicy();//强制信任证书。重写验证服务端证书的方法。
sResult = wcfServiceProxyHttp.SayHello(sName);
Console.WriteLine("Returned Result is {0}", sResult);
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
-
谢谢
您这个代码在2.0框架下能用么?我的客户端是2.0的框架
我没做过测试。但是之前写过Web Service的 用户名和密码验证。
首先定义一下自己的MySOAPheader类,继承自SOAPheader.和web service一个项目.主要是传递用户的票据,自己可以实现更复杂的定义,包括用户名称和密码等
WCF分布式开发必备知识(4):Web Service
2.0 调用 WCF的你再Google一下
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
-
期待版主的回复!!!!!!!!!
这个肯定可以实现,不过我没写Demo。网上应该也有,你可以Google一下啊,老外肯定写了
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
-
用basic的可以身份验证 我记得你说过你用的是selfhosted吧?你搜basichttpbinding username password有很多例子 e。g
http://nirajrules.wordpress.com/2009/05/22/username-over-https-custombinding-with-wcf%E2%80%99s-channelfactory-interface/
但是不清楚2.0的环境能不能用
我怀疑你用wshttpbinding更java很难沟通的 我现在也有这个问题 不过我用的是iis 所以上面的sample不适用:(
-
我看网上有文章介绍java调用wshttpbinding啊
http://social.msdn.microsoft.com/Forums/zh-CN/wcf/thread/ee4fc07b-b053-4446-b416-ecb1dd04cc7b
你会JAVA么?试试看?我不会那玩意
basichttpbinding的username身份验证,你试成功了吗?怎么配置的?
-
我弄出来basicHttpBinding下的UserName身份验证了,这是我的配置文件,你看这个算不算?
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation debug="true" /> </system.web> <system.serviceModel> <services> <service name="TeachInfoPlatform.TeachInfoService" behaviorConfiguration="WCFService.WCFServiceBehavior"> <host> <baseAddresses> <add baseAddress = "https://localhost:9000/" /> </baseAddresses> </host> <endpoint address ="SysUserManage" binding="basicHttpBinding" contract="TeachInfoPlatform.SystemManageContract.ISysUserManage" bindingConfiguration="bindingConfiguration"> </endpoint> <endpoint address="BasicData" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.IBasicData" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="LessonInfo" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.ILessonInfo" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="RoomInfo" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.IRoomInfo" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="StudentInfo" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.IStudentInfo" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="TeacherInfo" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.ITeacherInfo" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="ExperimentInfo" binding="basicHttpBinding" contract="TeachInfoPlatform.PublicContract.IExperimentInfo" bindingConfiguration="bindingConfiguration"></endpoint> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCFService.WCFServiceBehavior"> <serviceMetadata httpsGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> <serviceCredentials> <serviceCertificate storeName="My" x509FindType="FindBySubjectName" findValue="localhost" storeLocation="LocalMachine"/> <clientCertificate> <authentication certificateValidationMode="None"/> </clientCertificate> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TeachInfoPlatform.UserPasswordValidator,TeachInfoPlatform"/> </serviceCredentials> <serviceAuthorization serviceAuthorizationManagerType="TeachInfoPlatform.TeachServiceAuthorizationManager,TeachInfoPlatform"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <basicHttpBinding> <binding name="bindingConfiguration" useDefaultWebProxy="false"> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None"></transport> <message clientCredentialType="UserName"/> </security> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration>
配置成这样,Java就可以访问了????2.0可以访问吗?访问的时候,用户名和密码往哪填? -
你怎么才发现呀
我现在stuck在用httpmodule里面呢 因为我们想用iis比较规范点 结果iis host不支持username的 只能自己写个httpmodule 写了很难加上去
wcf的config很不好搞定 我现在都懒得看自己的code了
我也不清楚java怎么回事 你找的那个文章里是不是特指需要某种java的方法?
随手搜的:
http://stackoverflow.com/questions/1139285/consuming-a-wcf-wshttpbinding-webservice-in-java
Your problem is that JAX-WS doesn't support the same WS protocols that are used in the wsHttpBinding. You need to use WSIT instead. WSIT is available as part of the Metro library, which is also available on Glassfish.
I recommend using wsHttpBinding or ws2007HttpBinding where possible, but you can still do a fairly secure service with basicHttpBinding over SSL/Transport Auth.
-
我刚看到一个文章说你试试add web reference instead of add reference
-
还有一个思路就是用wse 3,在2.0上面是支持的 具体行不行我就不清楚了
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=018A09FD-3A74-43C5-8EC1-8D789091255D
做这个wcf我也觉得很烦 总是试来试去担心最后不成
good luck!
-
basicHttpBinding应该可以的。
USerName 和Password以明文形式在消息头里 传递。
这个应该是可以的,只要Java可以生成这样的SOAP消息即可。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/