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();
    
    
  • 相关阅读:
    linux based bottlerocket-os
    linux resolver
    linux hosts_access
    mysql performance storage engine
    linux security module机制
    linux seccomp使用和原理
    pxe过程和原理
    数据库
    python基础语法
    补充进程 线程和携程基础概念
  • 原文地址:https://www.cnblogs.com/HaibaraAi/p/5523482.html
Copyright © 2011-2022 走看看