zoukankan      html  css  js  c++  java
  • Wcf

    带基本身份验证通过帐号密码访问的Wcf
    PHP:

    $key="abc";
    $password="123";
    $url="http://127.0.0.1:1000";
    $client = new SoapClient ($url,
        array('trace'=>true,'exception'=>0,
        'login'=>$key,'password'=>$password,
        'connection_timeout'=>60,
        'authentication'=>SOAP_AUTHENTICATION_BASIC));
    $ret=$client->Add(array("num1"=>1,"num2"=>2));
    var_dump($ret);
    

    C#

    Uri wcfPath = new Uri("http://127.0.0.1:1000/Namespace");
    var bhb=new BasicHttpBinding();
    bhb.AllowCookies = false;
    bhb.TransferMode = TransferMode.Buffered;
    bhb.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    bhb.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    var client = new WcfTestClient(bhb,new EndpointAddress(wcfPath));
    client.ClientCredentials.UserName.UserName = "abc";
    client.ClientCredentials.UserName.Password = "123";
    

    .Net Server

    Type type=typeof(WcfTest);
    Uri baseAddress = new Uri("127.0.0.1:1000/Normal");
    Uri webAddress = new Uri("127.0.0.1:1000/Web");
    
    var wcfHost = new ServiceHost(type);
    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
    behavior.HttpGetEnabled = true;
    behavior.HttpGetUrl = new Uri("127.0.0.1:1000");
    wcfHost.Description.Behaviors.Add(behavior);
    wcfHost.Description.Name = "serviceTest";
    
    ContractDescription cd = ContractDescription.GetContract(type);
    WebHttpBinding wb = new WebHttpBinding();
    WebHttpBehavior whb = new WebHttpBehavior();
    
    whb.DefaultBodyStyle = WebMessageBodyStyle.Wrapped;
    whb.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
    
    ServiceEndpoint ep1 = new ServiceEndpoint(cd, wb, new EndpointAddress(webAddress));
    ep1.Behaviors.Add(whb);
    wcfHost.Description.Endpoints.Add(ep1);
    
    BasicHttpBinding bhb = new BasicHttpBinding();
    bhb.AllowCookies = false;
    bhb.TransferMode = TransferMode.Buffered;
    bhb.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    bhb.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    
    ServiceEndpoint ep = new ServiceEndpoint(cd, bhb, new EndpointAddress(baseAddress));
    wcfHost.Description.Endpoints.Add(ep);
    wcfHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
    wcfHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
    wcfHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new WcfValidator();
    
    wcfHost.Open();
    
    
  • 相关阅读:
    调试脚本的技巧与实际应用
    mysqlconnector将EXCEL表数据导入数据库
    第四十三节,文件、文件夹、压缩包、处理模块shutil
    第四十二节,configparser特定格式的ini配置文件模块
    第四十一节,xml处理模块
    第四十节,requests模拟浏览器请求模块初识
    第三十九节,python内置全局变量
    第三十八节,字符串格式化
    第三十七节,hashlib加密模块
    第三十六节,os系统级别操作模块
  • 原文地址:https://www.cnblogs.com/HaibaraAi/p/5523482.html
Copyright © 2011-2022 走看看