如何发送身份验证标头信息?

时间:2014-02-17 06:01:33

标签: c# .net wcf

我正在尝试使用WCF方法访问Java服务,我在该方法中添加了对解决方案的服务引用。该服务是托管在WAS服务器中的JAVA服务。发送的请求是以下信息,

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
    <VisSvcHeaders xmlns="http://dai.e.VisSvc/2010/svc">
        <packNGo>false</packNGo>
    </VisSvcHeaders>
    <wsa:Action>http://vissvc.e.com/2010/svc/getData</wsa:Action>
    <wsa:From>
        <wsa:Address>Vis</wsa:Address>
    </wsa:From>
    <wsa:MessageID>urn:uuid:6e1fd026-99cf-4abf-90f0-35f7803aa624</wsa:MessageID>
    <wsa:ReplyTo>
        <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:To>https://vissvc.e.intra.net/VisSvcNative/Service</wsa:To>
    <wsse:Security>
        <wsu:Timestamp wsu:Id="Timestamp-79d3f408-1f2b-45c9-a04c-448a3ceb6afe">
            <wsu:Created>2014-02-14T06:13:44Z</wsu:Created>
            <wsu:Expires>2014-02-14T06:18:44Z</wsu:Expires>
        </wsu:Timestamp>
    </wsse:Security>
</soap:Header>

前端代码段是

using (ServiceReference1.ServicePortTypeClient svc = new ServiceReference1.VisServicePortTypeClient())
        {
            svc.ClientCredentials.UserName.UserName = "username";
            svc.ClientCredentials.UserName.Password = "password";               
            ServiceReference1.ResponseType response = svc.getData();   
            Console.WriteLine("Connected");
        }

app.config文件是

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="WebServiceUrl" value="https://vissvc.e.intra.net/VisSvcNative/Servic"/>
<add key="LogoutUrl" value="http://login.e.corpintra.net/internal/logout"/>
</appSettings>
<system.net>
<defaultProxy >
<proxy autoDetect ="True" />
</defaultProxy>
</system.net>
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding>
        <security mode="TransportWithMessageCredential">
          <transport clientCredentialType="None" realm="VisService.intra"/>
          <message clientCredentialType="UserName" />
        </security>
      </binding>
      <binding name="VisSoapBinding" >    
      </binding>
    </basicHttpBinding>
   <client>
        <endpoint address="https://vissvc.e.intra.net/VisSvcNative/Servic"
            binding="basicHttpBinding" bindingConfiguration="VisSoapBinding"
            contract="ServiceReference1.VisServicePortType" name="VisServicePort" />
    </client>
    </system.diagnostics>
    </configuration>

我总是收到错误 “HTTP请求未经授权使用客户端身份验证方案'匿名'。从服务器收到的身份验证标头是'basic realm =”VisService.intra./VisSvcNative“'”。无论我改变安全模式,我都会遇到同样的错误。 请帮助我。

我正在使用.net c#4.0

0 个答案:

没有答案